How to get commit history for only one branch?

Say I created a new branch my_experiment from master and made some my_experiment for my_experiment . If I do a git log when on my_experiment , I see that the commits are made in this branch, but the records made in master also made before the my_experiments branch was created.

It would be very useful for me to see the history of all commits in the my_experiments branch until it hits the creation of this branch - in fact, this is the true history of only this branch. Otherwise, itโ€™s not clear to me, looking through the log, whether there were commits in the my_experiments branch or not.

Is there any way to do this with git?

+109
git git-log
Jun 07 '13 at 0:05
source share
6 answers

You can use range .

 git log master.. 

If you checked your branch my_experiment . This will compare where master is on HEAD (tip of my_experiment ).

+114
Jun 07 '13 at 0:06 on
source share

The git merge-base command can be used to search for a common ancestor. Therefore, if my_experiment has not yet been merged with the master, and my_experlement was created from the master, you could:

 git log --oneline `git merge-base my_experiment master`..my_experiment 
+6
Jun 07 '13 at 0:55
source share

Note: if you limit this log to the last n commit (the last 3 commit, for example, git log -3), do not forget to put a space between 'n' and your branch:

 git log -3 master.. 

Prior to git 2.1 (August 2014), this error was: git log -3master.. will actually show you the last 3 commits of the current branch (here my_experiment ), ignoring the limit of master (which means if my_experiment contains only one commit, 3 will still be listed, 2 of them from master )

See commit e3fa568 Junio โ€‹โ€‹C Hamano ( gitster ) :

version: parse " git log -<count> " more carefully

This confusing command line simply ignores " master " and ends up showing two commits from the current HEAD :

 $ git log -2master 

because we root " 2master " before atoi() without making sure that the whole string is parsed as an integer.

Instead, use the strtol_i() helper function.

+3
Aug 02 '14 at 18:37
source share

I think the option for your purposes is git log --oneline --decorate . This allows you to find out the verification commit, and the top one for each branch that is available in your plot line. By doing this, you have a great look at the structure of your repo and the commits associated with a particular branch. I think reading this could help.

+1
Mar 13 '17 at 13:42 on
source share

You can only use git log --oneline

+1
Mar 28 '19 at 11:08
source share

I know it is very late for this ... But here is (not so simple) oneliner to get what you were looking for:

 git show-branch --all 2>/dev/null | grep -E "\[$(git branch | grep -E '^\*' | awk '{ printf $2 }')" | tail -n+2 | sed -E "s/^[^\[]*?\[/[/" 
  • We list commits with the branch name and relative positions to the actual state of the branch using git show-branch (sending alerts to /dev/null ).
  • Then we leave in brackets only those that have a branch name using grep -E "\[$BRANCH_NAME" .
  • Where the actual $BRANCH_NAME obtained using git branch | grep -E '^\*' | awk '{ printf $2 }' git branch | grep -E '^\*' | awk '{ printf $2 }' git branch | grep -E '^\*' | awk '{ printf $2 }' (branch with a star reflected without this star).
  • From our results, we remove the extra line at the beginning with tail -n+2 .
  • And then we generally clear the output, removing everything that precedes [$BRANCH_NAME] with sed -E "s/^[^\[]*?\[/[/" .
0
Jul 29 '19 at 19:47
source share



All Articles