How can I keep track of where commits came from once they've been merged?

前端 未结 2 2074
迷失自我
迷失自我 2021-02-20 18:44

My company does not maintain the repository with git (we effectively use CVS), but I keep a repo locally for my own sanity. In the past, I\'ve wanted to bring up c

2条回答
  •  太阳男子
    2021-02-20 19:17

    merges-introducing() {
        # merges-introducing $introducing [$descendant]
        local introducing;
        if introducing=`git rev-parse $1`; then 
            shift
            git rev-list --ancestry-path --parents --reverse ^$introducing ${@-HEAD} \
            | awk '{seen[$1]=1} NR>1 && !seen[$2] {print $1}' \
            | xargs -r git show --oneline --no-patch
         fi
    }
    

    Finds the merges incorporating a commit from a merged history.

    git rev-list's --ancestry-path lists only the commits on the line of descent from the bottom commit (^$introducing here) to the top (default HEAD, your current checkout), --parents gives the parents for each of them, --reverse lists the commits oldest-first (so $introducing comes first), and the post-processing, the awk|xargs, prints only merges whose first parent isn't on that ancestry path.

    Unless someone's gone in and hand-edited the merge messages the subject lines for those commits will say the branch name and any source url of the relevant (and non-fastforward) merges, oldest first.

提交回复
热议问题