【问题标题】:show git branches with date of last commit显示带有最后提交日期的 git 分支
【发布时间】:2017-11-13 15:01:57
【问题描述】:

几周前我在一个分支上工作,但我不记得这个分支叫什么(有很多)。我希望能够做类似的事情:

git branch --print-last-commit

并让它输出如下内容:

branch 1 - 2017-02-12
branch 2 - 2016-12-30

等等

有什么办法吗?

【问题讨论】:

    标签: git version-control git-branch


    【解决方案1】:

    这将打印 BranchName - CommitMessage - Date as (YYYY-MM-DD)。您可以操作/编辑此命令行以满足您的需要。

    git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:short)%(color:reset))'
    

    请注意,它将打印所有本地分支,而不仅仅是当前分支。为方便起见,您可以创建一个别名。

    [alias]
           branchcommits = !git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:short)%(color:reset))'
    

    并在 git bash 提示符下运行 git branchcommits

    【讨论】:

      【解决方案2】:

      您可以使用以下命令获取每个分支的所有最后提交

      for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r
      

      更多信息https://gist.github.com/jasonrudolph/1810768

      【讨论】:

        【解决方案3】:

        我知道这篇文章很旧,但在其他答案的帮助下,我提出了另一个不涉及 bash for 循环的解决方案。

        $ paste  <(git branch | xargs -I {} git --no-pager show -q --format="%ci %cr" {} | tail -n +1) \
            <(git branch) | sort -h | tail -5
        2021-10-12 11:24:21 -0700 2 weeks ago     adamryman/foobar
        2021-10-12 15:20:18 -0700 2 weeks ago     adamryman/foobarbaz
        2021-10-26 16:46:25 -0700 3 days ago      adamryman/baz
        2021-10-27 19:00:14 -0700 2 days ago      adamryman/foobaz
        2021-10-28 14:03:48 -0700 21 hours ago    adamryman/barfoo
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-01-13
          • 2014-11-19
          • 2012-08-31
          • 2017-06-19
          • 2021-12-16
          • 2022-07-01
          • 2013-04-26
          相关资源
          最近更新 更多