How to get the list of files from a merge commit id

I am in master branch, I need to get the list of files in each commit id, I am not able to retrieve any files using the merge commit id, If a merge happens from a different branch to master, then if use the regular (git show or git diff tree) for the merge commit id it returns nothing. Basically I am not able to get the list of files that has been modified in differnt branch and merged to master. Is there a way to get the list of files using merge commit id ..??

Thanks in advance..!!

3 answers

1 accepted

This command will get the files in commit id.

git log -m -1 --name-only --pretty="format:" COMMITID
0 vote
Chris Fuller Atlassian Team Jun 07, 2014

git diff --stat is probably what you're after:

cfuller@crf:~/src/atlassian/jira [master]$ git show f2ba530
commit f2ba530462ecbe9ef12cc0d1bb5355ca09495475
Merge: 246473c f6100d6
Author: Richard Cordova <rcordova@atlassian.com>
Date:   Fri Jun 6 03:25:24 2014 +0000

    Merge pull request #1052 in JIRA/jira from issue/JDEV-27150 to release

    * commit 'f6100d6681211c819abe13c7ea543b7f64eadfde':
      JDEV-27150: Ensure only one node executes upgrade tasks

cfuller@crf:~/src/atlassian/jira [master]$ git diff --stat 246473c..f2ba5304
 jira-components/jira-plugins/jira-sal-plugin/src/main/java/com/atlassian/sal/jira/upgrade/JiraPluginUpgradeManager.java | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

Sometimes what you want is the other merge parent, but clearly not here:

cfuller@crf:~/src/atlassian/jira [master]$ git diff --stat f6100d6..f2ba530
 jira-components/jira-plugins/jira-bundled-plugins/pom.xml | 2 +-
 pom.xml                                                   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

This is because, for a merge, the list of modified files depend on which parent you are comparing from. For example, the merge of the branch 'foo' to the branch 'master' will have a different list of modified files if the comparison is 'foo -> merge' or 'master -> merge'.

So to see the list of modified files, just run the diff command indicating which parent you want the diff to be compared to:

  • for the first parent:
    git diff merge^ merge --name-status
  • or for the second parent:
    git diff merge^2 merge --name-status

And so on (merge^n) to compare to any other parent of the merge.

Note that the different notations supported by Git (commit^n, commit~n, etc.) are explained in the manual of the rev-parse command:

git help -w rev-parse

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 06, 2018 in Bitbucket

Do you use Bitbucket Cloud and Jira Cloud? If so, let us know!

Hi Community, I'm Julia and I'm on the Jira Software Cloud marketing team!  We're looking for companies or teams using Bitbucket Cloud and Jira Software Cloud. If your team fits the t...

87 views 3 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you