How do I run git log to see changes only for a specific branch?

GitBranchGit BranchGit Log

Git Problem Overview


I have a local branch tracking the remote/master branch. After running git-pull and git-log, the log will show all commits in the remote tracking branch as well as the current branch. However, because there were so many changes made to the remote branch, I need to see just the commits made to the current local branch.

What would be the Git command to use to only show commits for a specific branch?

Notes:

Configuration information:

[branch "my-branch"]
  remote = origin
  merge = refs/heads/master

Git Solutions


Solution 1 - Git

Assuming that your branch was created off of master, then while in the branch (that is, you have the branch checked out):

git cherry -v master

or

git log master..

If you are not in the branch, then you can add the branch name to the "git log" command, like this:

git log master..branchname

If your branch was made off of origin/master, then say origin/master instead of master.

Solution 2 - Git

Use:

git log --graph --abbrev-commit --decorate  --first-parent <branch_name>

It is only for the target branch (of course --graph, --abbrev-commit --decorate are more polishing).

The key option is --first-parent: "Follow only the first parent commit upon seeing a merge commit" (https://git-scm.com/docs/git-log)

It prevents the commit forks from being displayed.

Solution 3 - Git

If you want only those commits which are done by you in a particular branch, use the below command.

git log branch_name --author='Dyaniyal'

Solution 4 - Git

The problem I was having, which I think is similar to this, is that master was too far ahead of my branch point for the history to be useful. (Navigating to the branch point would take too long.)

After some trial and error, this gave me roughly what I wanted:

git log --graph --decorate --oneline --all ^master^!

Solution 5 - Git

just run git log origin/$BRANCH_NAME

Solution 6 - Git

On the develop branch, and wanting to see a list of recent PR's.

PROMPT> git log --first-parent --pretty=oneline 0a805f46957a957161c5ed4e08081edeed9b91e7..6aae236484dc1881f5dbdef0f529eb95c6ef7bd5
0a805f46957a957161c5ed4e08081edeed9b91e7 Merged PR 1984/3: Fixed crash 2.
8d51abb53403e10e6484dc3c0569a5792f1x3734 Merged PR 1984/2: Fixed crash 1.
6aae236484dc1881f5dbdef0f529eb95c6efcbd5 Merged PR 1984/1: Downgraded from windows 11 to windows 3.11.

Solution 7 - Git

For those using Magit, hit l and =m to toggle --no-merges and =pto toggle --first-parent.

Then either just hit l again to show commits from the current branch (with none of commits merged onto it) down to end of history, or, if you want the log to end where it was branched off from master, hit o and type master.. as your range:

enter image description here

Solution 8 - Git

This is a weasel new age GUI sideways answer, but anyways, in Xcode there is apparently a visual tool for that.enter image description here

Solution 9 - Git

git log $(git branch --show-current)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHighway of LifeView Question on Stackoverflow
Solution 1 - GitWayne ConradView Answer on Stackoverflow
Solution 2 - GityerlilbilginView Answer on Stackoverflow
Solution 3 - GitDyaniyal WilsonView Answer on Stackoverflow
Solution 4 - GitGPHemsleyView Answer on Stackoverflow
Solution 5 - GitMahdi PedramView Answer on Stackoverflow
Solution 6 - GitneoneyeView Answer on Stackoverflow
Solution 7 - GitunhammerView Answer on Stackoverflow
Solution 8 - GitAnton TropashkoView Answer on Stackoverflow
Solution 9 - GitCodeFarmerView Answer on Stackoverflow