标签云

微信群

扫码加入我们

WeChat QR Code

显示该文件有两版本变化

I want to merge two branches that have been separated for a while and wanted to know which files have been modified.

Came across this link: http://linux.yyz.us/git-howto.html which was quite useful.

The tools to compare branches I've come across are:

  • git diff master..branch
  • git log master..branch
  • git shortlog master..branch

Was wondering if there's something like "git status master..branch" to only see those files that are different between the two branches.

Without creating a new tool, I think this is the closest you can get to do that now (which of course will show repeats if a file was modified more than once):

  • git diff master..branch | grep "^diff"

Was wondering if there's something I missed...


How many others find the title of this question misleading? It is actually about finding the file differences between two branches. What I came here looking for was how to see file differences between two revisions on the same branch. Or am I the only one?

2018年05月23日01分39秒

SandeepanNath: with git there is no difference. You are ALWAYS referring to individual commits.

2018年05月23日01分39秒

SamuelO'Malley I am new to git and considering the seemingly common branching strategy wherein all the branches are finally merged to the master branch and ultimately the master is rolled out. Now, considering the event of a rollout, where the production is already at master, but behind the tip (by one revision if the last rollout happened after the last master merge), I would like to see the differences between these two revisions, to find out what would be rolled out. I would not like to look at the branch which was last merged. Correct me if I am wrong.

2018年05月24日01分39秒

SandeepanNath: instead of using the branch names then you can take the answers below and just specify the commit IDs instead. Or even refer the commits by their tag names if you create tags when rolling out.

2018年05月23日01分39秒

SandeepanNath You cannot compare 2 branches, you must specify the revision. So comparing 2 branches is comparing 2 revisions.

2018年05月23日01分39秒

+1, sometimes --name-only is handy too

2018年05月23日01分39秒

user446936 - you can see what the letters mean in the git status man page kernel.org/pub/software/scm/git/docs/git-status.html - in particular, M == modified, D == deleted

2018年05月24日01分39秒

git diff master..blabla -- gives me fatal: bad revision 'master..blabla'. git diff master blabla -- gives me fatal: bad revision 'master'. Any idea what's wrong? UPDATE: this repo does not have a branch named master, doh!

2018年05月23日01分39秒

git diff --name-status your_branch...master outputs the changes that occurred on master since your_branch was created from it

2018年05月23日01分39秒

Here is a link to more options when using git diff. git-scm.com/docs/git-diff

2018年05月23日01分39秒

If you have (highly recommended, imho) git color turned on (config --global color.ui true), you can skip the --color. (I have lks - lazy keyboard syndrome.)

2018年05月24日01分39秒

I'm with you on color! BTW I meant to say git config --global color.ui true - to be complete.

1970年01月01日00分03秒

Does not work, throws errors: fatal: ambiguous argument 'master..branchName': unknown revision or path not in the working tree.

2018年05月24日01分39秒

TomášZato sorry but you need to swap "branchName" with the name of your branch.

2018年05月23日01分39秒

Awesome. I have never thought of branching that way. I think this should be considered as part of the "best practices" when merging.

2018年05月24日01分39秒

When you merge the ba-marge back into ba, isn't there a potential to have to fix the conflicts again?

2018年05月24日01分39秒

Nope, you've already resolved them.

2018年05月23日01分39秒

EricAnderson Right, it's a graph. SVN sticks like gum under a school desk. thx.

2018年05月23日01分39秒

This has come in handy especially with large branches containing a lot of differences.

2018年05月24日01分39秒

David, that's a good point, although it'd be nice to just know what's going on before hand...

2018年05月23日01分39秒

Orwellophile I upload a video to show how to do it. I hope it will help to you.

2018年05月23日01分39秒

Wow, just for me, I feel special. I've bookmarked it in delicious.com for future reference and extra google-foo.

2018年05月23日01分39秒

May want to set meld as default difftool: git config --global diff.tool meld

2018年05月23日01分39秒

This is my favorite because it will use whatever difftool you configure.

2018年05月24日01分39秒

Finally an answer that helps me, I've been getting errors with everything else. The key trick is to get all branch names.

2018年05月23日01分39秒

the question seems to be about native git utility

2018年05月23日01分39秒