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

后端 未结 11 740
傲寒
傲寒 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:56

    Here's a function you can add to your bash_profile to make this easier.

    Usage when in a Git repository:

    • branch prints all local branches
    • branch -r prints all remote branches

    Function:

    branch() {
       local pattern="s/^..//"
       local arg=""
       if [[ $@ == "-r" ]]; then
          pattern="s/^..(.*?)( ->.*)?$/\1/"
          arg=" -r "
          echo '-r provided'
       fi
       for k in $(git branch $arg | perl -pe "$pattern"); do
          echo -e $(git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1)\\t$k
       done | sort -r
    }
    

提交回复
热议问题