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 bash
for counting number of commits: git log remotes/origin/feature --oneline | wc -l
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
.
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.
--first-parent <branch_name>
is the option. works !
--first-parent <branch_name>
also worked for me! I ended up with an alias to git log --first-parent $current_branch_name --no-merges
. In response to @EdRandall, it will show the commits on the branch + those from where it was branched. For example:
new_feature
from master. You add commits C and D to it. Then you add E and F to master. You then merge master to new_feature
. Using git log
on new_feature
, you'll see "merge master", F, E, D, C, A, B. Using git log --first-parent new_feature --no-merges
, you'll see D, C, A, B.
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'
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^!
^master^!
means exclude the commit at the head of the master branch as well as all its parents/ancestors.
just run git log origin/$BRANCH_NAME
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.
For those using Magit, hit l
and =m
to toggle --no-merges
and =p
to 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:
https://i.stack.imgur.com/cLpR9.gif
https://i.stack.imgur.com/KJCdv.png
git log $(git branch --show-current)
git log
and does not filter out the common commits between the current and parent branches.
Success story sharing
git log --no-merges master..
was exactly what I needed.--no-merges
may appear that it's only showing commits from a specific branch, but it's really only showing commits that did not result in a mergegit log --no-merges --pretty='%C(yellow)%h%d %Creset%an %Cgreen%ar:%Creset %s' --graph master..