Listing each branch and its last revision's date in Git

后端 未结 11 739
傲寒
傲寒 2020-11-29 15:07

I need to delete old and unmaintained branches from our remote repository. I\'m trying to find a way with which to list the remote branches by their last modified date, and

11条回答
  •  無奈伤痛
    2020-11-29 15:51

    Here is what I came up with after also reviewing this.

    for REF in $(git for-each-ref --sort=-committerdate --format="%(objectname)" \
        refs/remotes refs/heads)
    do
        if [ "$PREV_REF" != "$REF" ]; then
            PREV_REF=$REF
            git log -n1 $REF --date=short \
                --pretty=format:"%C(auto)%ad %h%d %s %C(yellow)[%an]%C(reset)"
        fi
    done
    

    The PREV_REF check is to remove duplicates if more than one branch points to the same commit. (As in a local branch that exist in the remote as well.)

    NOTE that per the OP request, git branch --merged and git branch --no-merged are useful in identifying which branches can be easily deleted.

    [https://git-scm.com/docs/git-branch]

提交回复
热议问题