[git] How do I see the commit differences between branches in git?

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.

This question is related to git logging branch git-log

The answer is


#! /bin/bash
if ((2==$#)); then
  a=$1
  b=$2
  alog=$(echo $a | tr '/' '-').log
  blog=$(echo $b | tr '/' '-').log
  git log --oneline $a > $alog
  git log --oneline $b > $blog
  diff $alog $blog
fi

Contributing this because it allows a and b logs to be diff'ed visually, side by side, if you have a visual diff tool. Replace diff command at end with command to start visual diff tool.


You can easily do that with

git log master..branch-X

That will show you commits that branch-X has but master doesn't.


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]

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


Not the perfect answer but works better for people using Github:

enter image description here

Go to your repo: Insights -> Network


I used some of the answers and found one that fit my case ( make sure all tasks are in the release branch).

Other methods works as well but I found that they might add lines that I do not need, like merge commits that add no value.

git fetch
git log origin/master..origin/release-1.1 --oneline --no-merges

or you can compare your current with master

git fetch
git log origin/master..HEAD --oneline --no-merges

git fetch is there to make sure you are using updated info.

In this way each commit will be on a line and you can copy/paste that into an text editor and start comparing the tasks with the commits that will be merged.


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

If you want to compare based on the commit messages, you can do the following:

git fetch
git log --oneline origin/master | cut -d' ' -f2- > master_log
git log --oneline origin/branch-X | cut -d' ' -f2- > branchx_log
diff <(sort master_log) <(sort branchx_log)

if you want to use gitk:

gitk master..branch-X

it has a nice old school GUi


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to logging

How to redirect docker container logs to a single file? Console logging for react? Hide strange unwanted Xcode logs Where are logs located? Retrieve last 100 lines logs Spring Boot - How to log all requests and responses with exceptions in single place? How do I get logs from all pods of a Kubernetes replication controller? Where is the Docker daemon log? How to log SQL statements in Spring Boot? How to do logging in React Native?

Examples related to branch

Get git branch name in Jenkins Pipeline/Jenkinsfile Why do I have to "git push --set-upstream origin <branch>"? Your configuration specifies to merge with the <branch name> from the remote, but no such ref was fetched.? When does Git refresh the list of remote branches? Fix GitLab error: "you are not allowed to push code to protected branches on this project"? Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: Merge a Remote branch locally git pull from master into the development branch Depend on a branch or tag using a git URL in a package.json? How can I copy the content of a branch to a new local branch?

Examples related to git-log

How to get commit history for just one branch? How do I see the commit differences between branches in git? Commit history on remote repository How to exit git log or git diff How to search a Git repository by commit message? Get a list of all git commits, including the 'lost' ones How do I run git log to see changes only for a specific branch? How can I view a git log of just one user's commits? Viewing unpushed Git commits How to view file history in Git?