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

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

    Here is what I use:

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

    This is the output:

    2014-01-22 11:43:18 +0100       refs/heads/master
    2014-01-22 11:43:18 +0100       refs/heads/a
    2014-01-17 12:34:01 +0100       refs/heads/b
    2014-01-14 15:58:33 +0100       refs/heads/maint
    2013-12-11 14:20:06 +0100       refs/heads/d/e
    2013-12-09 12:48:04 +0100       refs/heads/f
    

    For remote branches, just use "refs/remotes" instead of "refs/heads":

    git for-each-ref --sort='-committerdate:iso8601' --format=' %(committerdate:iso8601)%09%(refname)' refs/remotes
    

    Building on n8tr's answer, if you are also interested in the last author on the the branch, and if you have the "column" tool available, you can use:

    git for-each-ref --sort='-committerdate:iso8601' --format='%(committerdate:relative)|%(refname:short)|%(committername)' refs/remotes/ | column -s '|' -t
    

    Which will give you:

    21 minutes ago  refs/remotes/a        John Doe
    6 hours ago     refs/remotes/b        Jane Doe
    6 days ago      refs/remotes/master   John Doe
    

    You may want to call "git fetch --prune" before to have the latest information.

提交回复
热议问题