obtaining full file paths in git merge
I'm working on a tool to analyse the output of merging many topic branches and produce a detailed conflict report. I've run into a slight problem in that sometimes Git will produce a truncated file name in the merge command's output, such as
Merge ma开发者_如何学Gode by recursive.
.../somepath/anotherpath/toolong/default.css | 2 +-
When in other cases it gives the full path
Auto-merging thefullpath/to/myfile/default.jsp
I would like to always have the full path available in order to match files between merges.
I'm a little confused by your end goal, but I think I can provide an answer anyway.
If you want to get a good report of changes when a merge runs into conflicts, i.e. while everything is still uncommitted, you should use git status --porcelain
. It gives a nice, machine-readable list of all files and their statuses (including merge conflict states) and is well-documented in the manpage. Depending on your use case, you might even use git merge --no-commit
to ensure you have the chance to inspect the merge result before proceeding (committing). You could also use git diff HEAD --numstat
to get a machine-readable report of the added/removed line counts by file.
If you want to examine merges after the fact, it's a very good use case for git diff-tree
:
git diff-tree -c --numstat <commit>
The -c
tells it to diff merge commits against both parents, and the --numstat
gets you a nice machine-readable output as before.
Finally, if you wanted to generate extremely detailed conflict reports, you could pass -p
instead of --numstat
, giving you full patch output. This is the kind of patch you'll see in gitk
, where there are two characters at the start of each line, indicating whether the line was added/removed relative to each parent. Changes coming from just one parent have just one symbol (e.g. '+ '
, ' -'
, quotes added to make spaces visible), while lines changed manually as part of conflict resolution will have two (--
, ++
). You could parse it yourself if you really had to. (Unfortunately I don't think there's anything like --numstat
on steroids for merge commits.)
精彩评论