1

When I do git commit -a, it opens the editor, in which the changes to be committed are commented out. I always uncomment these lines manually.

Is there a way to configure git to include those lines by default?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68
  • 2
    Why exactly do you want that? – Felix Kling Nov 29 '15 at 19:43
  • 1
    Possible duplicate of [How can I change the default comments in the git commit message?](http://stackoverflow.com/questions/3966714/how-can-i-change-the-default-comments-in-the-git-commit-message) – fracz Nov 29 '15 at 19:43
  • @FelixKling May be because I do not know an easier way to get to that information than to look through the output of `git log`... (I am new to using `git` or any version control for that matter) – AlwaysLearning Nov 29 '15 at 19:46
  • 4
    @AlwaysLearning, you should see [how to list changed files in a commit](http://stackoverflow.com/questions/21515084/list-files-modified-for-particular-git-commit) then. – fracz Nov 29 '15 at 19:51
  • @fracz Great link! I do prefer "modified" and "new file" instead of the laconic "M" and "A", though. – AlwaysLearning Nov 29 '15 at 20:13
  • git would not be very useful if you couldn't see what changed in each commit... :) – Eevee Nov 29 '15 at 20:42

1 Answers1

0

As already mentioned in the various comments, it is not a good idea to do that. A commit message should explain, why you did something - the what is already in the commit itself and can be checked via git show --name-status <commit>.

Nevertheless, if you need this functionality, you can add this as a prepare-commit-msg-hook, which lives in .git/hooks/prepare-commit-msg and might look like this:

#!/bin/bash
git diff --name-status -r >> $1

This will essentially give you a list of differences of the stage.

Lars
  • 5,757
  • 4
  • 25
  • 55
  • Using `git show --name-status ` makes it a two-stage process -- first using `git log` to look up the commit ID and then using `git show`. Also, `git show` displays the cryptic `M` instead of the clear `modified` and the cryptic `A` instead of the clear `new file`. Of course, one can get used to these, but it is still an extra (and unnecessary) background processing in the brain. So, is there a way to make this information be displayed in a human-readable format when I do `git log`? – AlwaysLearning Nov 30 '15 at 06:07
  • `git log --name-status` will print names and statuses for changed files, for each commit. Changing the M to modified sounds like a job for `sed`. If you want to get fancier, git comes with a graphical tool which you can access using `git gui`, and many third-party GUIs exist. – johncip Nov 30 '15 at 10:06