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

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

    Building off of Olivier Croquette, I like using a relative date and shortening the branch name like this:

    git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads
    

    Which gives you output:

    21 minutes ago  nathan/a_recent_branch
    6 hours ago        master
    27 hours ago    nathan/some_other_branch
    29 hours ago    branch_c
    6 days ago      branch_d
    

    I recommend making a Bash file for adding all your favorite aliases and then sharing the script out to your team. Here's an example to add just this one:

    #!/bin/sh
    
    git config --global alias.branches "!echo ' ------------------------------------------------------------' && git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads && echo ' ------------------------------------------------------------'"
    

    Then you can just do this to get a nicely formatted and sorted local branch list:

    git branches
    

提交回复
热议问题