60

I'm thinking if there is a way that when I merge a branch into another branch that ALL changed files are listed in my commit message and not just the ones which were modified in both branches. This would give me a better overview of what was changed in the branch just by seeing the merge commit. Is there a way to do this?

soupdiver
  • 3,504
  • 9
  • 40
  • 68

3 Answers3

92

I don't know how to do that in the commit message. But after the merge, this will give the names of all the files affected by the merge commit:

git log -m --name-only

For only a list of filenames of the commit:

git log -m -1 --name-only --pretty="format:" <Merge SHA>

There is some white space due to the merge having two parents but that can be easily removed.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Schleis
  • 41,516
  • 7
  • 68
  • 87
  • this also justs lists all the commits (of course incl. the file names) but I just want to have a list of files – soupdiver Feb 05 '13 at 21:26
  • add a -1 to the command. Updated my answer further to only show file names. – Schleis Feb 05 '13 at 21:37
  • 3
    Thanks for this! I can't find `-m` or `-1` documented anywhere today (though they still work). Have these options ben renamed? – Johann Oct 28 '14 at 17:04
  • 4
    The -1 is in the documentation as -, you can limit the log to any number of commits. I can seem to find the documentation for `-m` either though but it is shown as one of the examples. – Schleis Oct 28 '14 at 18:12
  • 12
    **-m** is for the following and is a *diff formatting* option: This flag makes the merge commits show the full diff like regular commits; for each merge parent, a separate log entry and diff is generated. An exception is that only diff against the first parent is shown when --first-parent option is given; in that case, the output represents the changes the merge brought into the then-current branch. – d48 Jan 07 '15 at 19:04
  • 3
    -m is in the Diff Formatting section of `git help log`. It unfortunately does not have a long option name. – Elijah Lynn Mar 30 '17 at 21:55
  • @elijah : or `git log help`. – Timo Dec 12 '17 at 17:53
  • `-m -1` returns for some reason all commits merged in current branch, so I use `git diff --name-only HEAD HEAD~1` from @R0MANARMY' s answer – vladkras Jul 09 '18 at 09:34
16

You can also use the diff command to see the difference between any two commits. If the branches haven't been merged yet, you can specify the branch names and compare them, otherwise you might need to find where they diverged (like so) an the last commit before they were merged back together.

git diff --name-status <commit> <commit>

-name-status Show only names and status of changed files. 

Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84
5

suppose you have SHA of your merge commit, then git diff --name-only <SHA>^1 <SHA>

evgenii
  • 285
  • 2
  • 7