Git log to get commits only for a specific branch

后端 未结 12 1705
挽巷
挽巷 2020-11-29 15:13

I want to list all commits that are only part of a specific branch.

With the following, it lists all the commits from the branch, but also from the parent (master)

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 15:44

    I needed to export log in one line for a specific branch.

    So I probably came out with a simpler solution.
    When doing git log --pretty=oneline --graph we can see that all commit not done in the current branch are lines starting with |

    So a simple grep -v do the job:
    git log --pretty=oneline --graph | grep -v "^|"

    Of course you can change the pretty parameter if you need other info, as soon as you keep it in one line.

    You probably want to remove merge commit too.
    As the message start with "Merge branch", pipe another grep -v and you're done.

    In my specific ase, the final command was:
    git log --pretty="%ad : %an, %s" --graph | grep -v "^|" | grep -v "Merge branch"

提交回复
热议问题