This answer is great for seeing a visual diff between two files that are checked into git: How do I view 'git diff' output with a visual diff program?
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?
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
For those of you on Windows using TortoiseGit, you can get a somewhat visual comparison through this rather obscure feature:
shift
and right-click itctrl
to select two branches to compareUPDATE
Mac: I now use SourceTree. Thoroughly recommended. I especially like the way you can stage / unstage hunks.
Linux: I've had success with:
meld
E.g. to install smartgit
on Ubuntu:
.deb
from https://www.syntevo.com/smartgit/download/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
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
In case you are using Intellij Idea IDE, you could just use the compare option in the branch.
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.
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.
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)
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: Differences between git branches using Visual Studio.
If you use Eclipse you can visually compare your current branch on the workspace with another tag/branch:
git show-branch
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
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.
You can also use vscode to compare branches using extension CodeLense, this is already answered in this SO: How to compare different branches on Visual studio code
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:
$ git mergetool
and $ git difftool
to use p4merge$ git diff
will still just use the default inline diff viewer :) (tested with git version 1.8.2)[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\""
Source: Stackoverflow.com