How to get commit history for just one branch?

前端 未结 6 1224
北荒
北荒 2020-12-23 12:56

Let\'s say I created a new branch my_experiment from master and made several commits to my_experiment. If I do a git log

6条回答
  •  一生所求
    2020-12-23 13:40

    I know it's very late for this one... But here is a (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 are listing commits with branch name and relative positions to actual branch states with git show-branch (sending the warnings to /dev/null).
    • Then we only keep those with our branch name inside the bracket with grep -E "\[$BRANCH_NAME".
    • Where actual $BRANCH_NAME is obtained with git branch | grep -E '^\*' | awk '{ printf $2 }' (the branch with a star, echoed without that star).
    • From our results, we remove the redundant line at the beginning with tail -n+2.
    • And then, we fianlly clean up the output by removing everything preceding [$BRANCH_NAME] with sed -E "s/^[^\[]*?\[/[/".

提交回复
热议问题