git visual diff between branches
GitDiffGit Problem Overview
This answer is great for seeing a visual diff between two files that are checked into git: https://stackoverflow.com/questions/255202/how-do-i-view-git-diff-output-with-a-visual-diff-program/949242#949242
However, I'd like to see a visual diff between two branches. So far, my best bet seems to be:
git diff --name-status master dev
which isn't very informative and not very visual.
Is there anything better out there?
Git Solutions
Solution 1 - Git
git diff branch1..branch2
This will compare the tips of each branch.
If you really want some GUI software, you can try something like SourceTree which supports Mac OS X and Windows.
Solution 2 - Git
To see a visual diff of all differences between two branches I like to merge the two branches - WITHOUT committing the merge - and then use git gui
or git Extensions to get an overview of the differences.
Git command line for merging without commiting:
git checkout branchA git merge --no-commit --no-ff branchB
Then when done, you can undo the merge with
git merge --abort(h/t to @jcugat's for the comment)
Solution 3 - Git
In case you are using Intellij Idea IDE, you could just use the compare option in the branch.
Solution 4 - Git
You can also do this easily with gitk.
> gitk branch1 branch2
First click on the tip of branch1. Now right-click on the tip of branch2 and select Diff this->selected.
Solution 5 - Git
For those of you on Windows using TortoiseGit, you can get a somewhat visual comparison through this rather obscure feature:
- Navigate to the folder you want to compare
- Hold down
shift
and right-click it - Go to TortoiseGit -> Browse Reference
- Use
ctrl
to select two branches to compare - Right-click your selection and click "Compare selected refs"
Solution 6 - Git
If you are using OSX or Windows 7+, Atlassian SourceTree works very well for this. It is free.
You can see staged changes in a side-by-side diff setup, and you easily compare local with remote and any other two branches. When multiple files are selected, the diff shows up as below:
Assuming you have checked out a feature branch and you want to see the diff against 'master', right-click on the 'master' branch and select "Diff against current"
Unfortunately, it doesn't seem as if it will be available on *nix distributions anytime soon.
Solution 7 - Git
Try "difftool" (assuming you have diff tools setup) - see https://www.kernel.org/pub/software/scm/git/docs/git-difftool.html
I find name status good for the summary but difftool will iterate the changes (and the -d
option gives you the directory view), e.g.
$ git difftool their-branch my-branch
Viewing: 'file1.txt'
Launch 'bc3' [Y/n]:
...
Or as @rsilva4 mentioned with -d
and default to your current branch it is just - e.g. compare to master:
$ git difftool -d master..
...and yes - there are many variations - https://www.kernel.org/pub/software/scm/git/docs/git-reset.html
Solution 8 - Git
In GitExtensions you can select both branches in revision grid with Ctrl pressed. Then you can see files that differ between those branches. When you select a file you will see diff for it.
Taken from here
Or you can right-click on any revision and choose Compare > Compare Branch...
Then you get to choose which branch to compare to:
And you end up with a Diff window listing the files that are different between the two branches, and for each file it shows a diff view.
Solution 9 - Git
If you're using github you can use the website for this:
github.com/url/to/your/repo/compare/SHA_of_tip_of_one_branch...SHA_of_tip_of_another_branch
That will show you a compare of the two.
Solution 10 - Git
UPDATE
Mac: I now use SourceTree. Thoroughly recommended. I especially like the way you can stage / unstage hunks.
Linux: I've had success with:
- smartgit
- GitKraken
meld
E.g. to install smartgit
on Ubuntu:
- download the
.deb
from https://www.syntevo.com/smartgit/download/ - install with sudo dpkg -i /path/to/deb`
This does the job:
git-diffall with a GUI diff tool like meld. See point 5 here:
http://rubyglazed.com/post/15772234418/git-ify-your-command-line
There's a nice post about git and meld here: http://nathanhoad.net/how-to-meld-for-git-diffs-in-ubuntu-hardy
Solution 11 - Git
If you use Eclipse you can visually compare your current branch on the workspace with another tag/branch:
Solution 12 - Git
You can use the free P4Merge from Perforce to do this as well:
http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools
Details on integrating it with Git can be found here and here
but a quick summary from the above links is:
- Put the following bits in your ~/.gitconfig, and then you can do
$ git mergetool
and$ git difftool
to use p4merge - Note that
$ git diff
will still just use the default inline diff viewer :) (tested with git version 1.8.2)
Changes for .gitconfig
[merge]
keepBackup = false
tool = p4merge
[mergetool "p4merge"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$PWD/$BASE\"" "\"$PWD/$REMOTE\"" "\"$PWD/$LOCAL\"" "\"$PWD/$MERGED\""
keepTemporaries = false
trustExitCode = false
keepBackup = false
[diff]
tool = p4merge
[difftool "p4merge"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$REMOTE\"" "\"$LOCAL\""
Solution 13 - Git
Solution 14 - Git
git show-branch
Have a look at There's a lot you can do with core git functionality. It might be good to specify what you'd like to include in your visual diff. Most answers focus on line-by-line diffs of commits, where your example focuses on names of files affected in a given commit.
One visual that seems not to be addressed is how to see the commits that branches contain (whether in common or uniquely).
For this visual, I'm a big fan of git show-branch
; it breaks out a well organized table of commits per branch back to the common ancestor.
-
to try it on a repo with multiple branches with divergences, just type
git show-branch
and check the output -
for a writeup with examples, see Compare Commits Between Git Branches
Solution 15 - Git
Here is how to see the visual diff between whole commits, as opposed to single files, in Visual Studio (tested in VS 2017). Unfortunately, it works only for commits within one branch: In the "Team Explorer", choose the "Branches" view, right-click on the repo, and choose "View history" as in the following image.
Then the history of the current branch appears in the main area. (Where branches that ended as earlier commits on the current branch are marked by labels.) Now select a couple of commits with Ctrl-Left, then right click and select "Compare Commits..." from the pop-up menu.
For more on comparing branches in the Microsoft world, see this stackoverflow question: https://stackoverflow.com/questions/37052450/differences-between-git-branches-using-visual-studio.
Solution 16 - Git
You can also use vscode to compare branches using extension CodeLense, this is already answered in this SO: https://stackoverflow.com/q/42112526/2781524