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.