Git log to get commits only for a specific branch

后端 未结 12 1694
挽巷
挽巷 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:42

    You could try something like this:

    #!/bin/bash
    
    all_but()
    {
        target="$(git rev-parse $1)"
        echo "$target --not"
        git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
        while read entry
        do
            eval "$entry"
    
            test "$ref" != "$target" && echo "$ref"
        done
    }
    
    git log $(all_but $1)
    

    Or, borrowing from the recipe in the Git User's Manual:

    #!/bin/bash
    git log $1 --not $( git show-ref --heads | cut -d' ' -f2 | grep -v "^$1" )
    

提交回复
热议问题