Git - How to compare files from two different branches

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what s different. Are there any ways to do this?

  To be clear    I m not looking for a compare tool (I use Beyond Compare). I m looking for a git diff command that will allow me to compare the master version to my current branch version to see what has changed. I m not in the middle of a merge or anything. I just want to say something like 
git diff mybranch/myfile.cs master/myfile.cs

Answers

git diff can show you the difference between two commits:

git diff mybranch master -- myfile.cs

Or, equivalently:

git diff mybranch..master -- myfile.cs

Using the latter syntax, if either side is HEAD it may be omitted (e.g. master.. compares master to HEAD).

https://git-scm.com/docs/git-diff https://git-scm.com/docs/git-diff

This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. git diff A...B is equivalent to git diff $(git-merge-base A B) B.

In other words, this will give a diff of changes in master since it diverged from mybranch (but without new changes since then in mybranch).


http://stackoverflow.com/a/13321491/54249 http://stackoverflow.com/a/13321491/54249


The same arguments can be passed to git difftool if you have one configured.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/4099742/how-to-compare-files-from-two-different-branches

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils