How do I see the commit differences between branches in git?
Solution 1
You can get a really nice, visual output of how your branches differ with this
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative master..branch-X
Solution 2
You can easily do that with
git log master..branch-X
That will show you commits that branch-X has but master doesn't.
Solution 3
I think it is matter of choice and context.I prefer to use
git log origin/master..origin/develop --oneline --no-merges
It will display commits in develop which are not in master branch.
If you want to see which files are actually modified use
git diff --stat origin/master..origin/develop --no-merges
If you don't specify arguments it will display the full diff.
If you want to see visual diff, install meld
on linux, or WinMerge
on windows. Make sure they are the default difftools .Then use something like
git difftool -y origin/master..origin/develop --no-merges
In case you want to compare it with current branch. It is more convenient to use HEAD instead of branch name like use:
git fetch
git log origin/master..HEAD --oneline --no-merges
It will show you all the commits, about to be merged
Solution 4
I'd suggest the following to see the difference "in commits". For symmetric difference, repeat the command with inverted args:
git cherry -v master [your branch, or HEAD as default]
Solution 5
If you are on Linux, gitg
is way to go to do it very quickly and graphically.
If you insist on command line you can use:
git log --oneline --decorate
To make git log
nicer by default, I typically set these global preferences:
git config --global log.decorate true
git config --global log.abbrevCommit true
Son of the Wai-Pan
Updated on July 08, 2022Comments
-
Son of the Wai-Pan almost 2 years
I'm on branch-X and have added a couple more commits on top of it. I want to see all the differences between MASTER and the branch that I am on in terms of commits. I could just do a
git checkout master git log
and then a
git checkout branch-X git log
and visually diff these, but I'm hoping for an easier, less error-prone method.
-
Pablo Fernandez heelhook over 11 yearsThat won't show you differences between branches though which is what is being asked.
-
Pablo Fernandez heelhook over 11 years
git log --oneline --graph --all --decorate --abbrev-commit
will give you a similar output in a shorter/more readable command -
Son of the Wai-Pan over 11 yearsI like this:
git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'
-
Shawn Erquhart about 9 yearsExtremely overcomplicated.
-
Dave almost 9 yearsdo this:
alias diff-branches="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
. Then do thisdiff-branches master..branch-X
. Now it's not complicated. -
avmohan over 8 years
git log --oneline --graph --all --decorate
is enough,--abbrev-commit
is not required,--oneline
is short for--pretty=oneline --abbrev-commit
-
cp.engr over 8 years@ShawnErquhart, you could alias as Dave suggests, or you could add the alias to your
~/.gitconfig
. -
cp.engr over 8 years@Avery, the
--all
switch in yours shows more than just the difference requested. -
Elliott Slaughter over 8 yearsIs there an option if both branches contain commits that the other doesn't? Right now, you have to flip the arguments and run it both ways to see commits the other branch doesn't contain.
-
Dave about 8 yearsIf you've already switched to
branch-X
you can usegit log master..
-
Xavier T. almost 8 years@ElliottSlaughter: If you want to find commit that are either in master or branch-X but not both, you can use
git log master...branch-X
(three dots instead of two). Seeman gitrevisions
for more info. -
jterm about 7 yearsIts really only half the answer. Any commits in master that cause the branches to diverge won't show up
-
pkamb over 6 yearsAlso, creating a Pull Request will also show the branch differences.
-
Tuffwer over 6 yearsIf commits have been cherry-picked from branch-X to master this won't filter them out. They will still be on the list of commits "In branch-X but not on master" even though they are actually in both..
-
Ashutosh Chamoli about 5 yearsUsing double quotes instead of single like below works for me
git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset" --abbrev-commit --date=relative master..branch-X
-
claudiu.f.marginean almost 5 yearsIf you compare a release branch that might have merges. You may like remove the merge commits (that do not add any value) with the help of the param
--no-merges
like:git log origin/master..HEAD --oneline --no-merges
-
ilmirons almost 5 yearsIs this different from git master..branch-X?
-
mmaruska almost 5 yearsSure, "git cherry" is smart: it translates from "commits" into "patches/diffs" and can avoid reporting a "patch" which is on both branches but applied in different order.
-
opticyclic over 4 yearsInstead of using
--oneline
and piping tocut
you can usegit log --format='%s'
-
noamgot almost 4 yearsSimilarly to @Dave 's suggestion - if you're on branch
mater
then dogit log ..branc-X
-
abcd over 3 yearsthe
--decorate
flag is no longer necessary either, as of version 2.13 -
Diogo Cardoso about 3 yearsOutputs the SHA1 of every commit, prefixed with - for commits that have an equivalent in master, and + for commits that do not.
-
larsl about 3 yearsThis works especially well with patch-based workflows where commits are often cherry-picked and applied to other branches.
-
Peter Out about 3 yearsGit log shows you what commits are in branch a that are not in branch b. Thus the order in which you supply the branches dictates the output. This is totally different to what git diff does and as such does not answer the question.
-
JHBonarius almost 3 yearsTHIS!!! THANKS! Else I get "unknown revision or path not in the working tree."
-
alper almost 3 yearsCan gitk open in dark-mode?
-
Franco Gil over 2 yearsThis only work for Public repos., what if I have a Private repo and the admin does not provide me all the access to response the question? For this current answer is not valid.
-
pushkarajthorat over 2 yearsjust invert the colors of the window