4

Is there any command to list only auto merged files in git after taking pull. Auto merging is not forcing us to watch code. Some time I needed to check explicitly to automerged files.

Git enlists changed files generally in three types in mix up. New files comes or old file deleted, auto merged and conflict.if git internally identifies automered files so I just thought there would be any command to list only auto merged files.by the way I want to get this list before the merge commit.

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
  • Do you want this list *before* or *after* the merge becomes a merge-commit? I'd also note that if, e.g., you pick up a change to file F from your merged-in branch, and there is no change to F in your own branch, F is not an "auto merged file" (or at least I would not call it one) but a change in that file may cause issues depending on how your other files (also possibly not "auto merged") use something in F. So I'm not really sure how useful such a list would be. – torek Jan 13 '16 at 17:36
  • Git enlists changed files generally in three types in mix up. New files comes or old file deleted, auto merged and conflict.if git internally identifies automered files so I just thought there would be any command to list only auto merged files.by the way I want to get this list before the merge commit. – Niklesh Raut Jan 13 '16 at 17:51

1 Answers1

3

For clarity in this answer, let's start with a few definitions and notes:

  • To perform a merge, git must find the "merge base", which (very loosely) is "a commit at which the current branch and the to-be-merged branch share development history".
  • You are doing a merge now and have either used --no-commit or gotten a merge conflict. If the latter, you have not resolved these conflicts already.
  • Thus, your work-tree has files ready to commit, but you have not actually made the commit.
  • A merge, once committed, has two parent commits. One is the commit that was the tip of the branch you were on just before you made the merge commit. Since you have not yet made the merge commit, your current HEAD commit is the tip of this branch now. So the phrase "the HEAD commit" below means "the tip of the branch before doing the merge".
  • Meanwhile, we also need a short word or phrase for the commit from the to-be-merged-in branch (which will become the second parent). I will call this the "inbound" commit. (I have not seen this term elsewhere, I just made it up after going through some thesaurus entries.)

Based on your comment-reply, I believe you want to find files that have any change from the HEAD commit, i.e., those that have picked up any changes from the inbound commit, whether or not git has merged those without finding a conflict.

If this is correct, the answer is quite simple:

git diff --cached --name-only

will list them. (This is a bit of a surprise since git diff --cached without --name-only does not show the unmerged files.)

Should you want only files git has (or thinks it has) successfully merged:

git status --porcelain | awk '/^M / { print $2 }'

will list those. (Leave out the awk, and optionally use -s or --short instead of --porcelain, to see the output from git status. In this case we look for files whose state is "merged, ready to commit". Files with merge conflicts will be in M state.)

You may also want to compare files to their merge-base versions. This is not too difficult except in the (somewhat rare) case of multiple merge-bases. I will leave these details out of this answer, though.

torek
  • 448,244
  • 59
  • 642
  • 775