【问题标题】:Show all stashes in git log在 git log 中显示所有存储
【发布时间】:2013-02-05 23:45:46
【问题描述】:

我想查看git log 输出中的所有存储。有谁知道有没有办法做到这一点?

编辑:我想记录所有提交。我使用命令

git log --date-order --all

但它只返回最顶层的存储。我希望看到代表其他存储的提交。

【问题讨论】:

    标签: git git-log git-stash


    【解决方案1】:

    您可以使用git stash list 显示您的所有藏匿处。也许您可以编写一个脚本来同时显示git stash listgit log 并将其与别名一起使用。

    【讨论】:

      【解决方案2】:

      我来这里是为了和@jbialobr 做同样的事情,在阅读了以前的答案后,我做了更多的挖掘,并得出了以下结论。

      @msmt 的回答为您提供了存储日志,您可以使用它来获取要在 git 日志中使用的哈希值。

      git reflog show --format="%h" stash 只为您提供所有存储的哈希值,然后可以将其传递给 git log 命令,例如

      git log --date-order --all $(git reflog show --format="%h" stash)

      我个人现在使用的完整命令是

      git log --oneline --graph --decorate --all $(git reflog show --format="%h" stash)

      在 centos 的 git 版本 2.5.1 上测试

      【讨论】:

      • SicoAnimal,你是一个了不起的人。您对 SO 的唯一贡献,[直到现在;一年多] 0票,绝对是配置文件的票。谢谢!
      • 我会使用 xargs ,因为它更具可读性和更易于使用:git reflog show --format="%h" stash | xargs git show
      【解决方案3】:

      不确定你的意思。 stash 是一个分支,您可以使用git log -g stash 列出所有存储。

      【讨论】:

      • 更好的是,它显示了所有存储,但现在它不显示与存储相关的索引和未跟踪文件提交。命令 git log -z --all --boundary 显示它们,但是当我添加 -g stash 时,这些提交不再出现在日志输出中。
      • 再详细说明一下:stash 是所有存储头列表的refs/stash 的缩写,-g(或--walk-refs)告诉log通过参考列表中的项目,而不是从每次存储提交中跟踪修改历史。
      【解决方案4】:

      另一个简单的方法是git reflog show stash

      【讨论】:

      • 你读过我的编辑笔记吗?我知道如何列出藏匿处。我想在git log 命令的输出中包含所有存储。
      • @jbialobr 我想你的问题对我来说有点模棱两可。看起来您知道如何记录所有提交,但您正在寻找如何仅查看存储。对我来说模棱两可的是,I would like to see commits that represent other stashes. 如果git log --all 不适合你,那么我将不得不支持@robinr 所说的“不确定你的意思”。
      【解决方案5】:

      完整命令:

      git log --oneline --graph --all $(git stash list --format="%H")

      藏匿处列表:

      git stash list --format="%H"

      【讨论】:

        【解决方案6】:

        要获得包含所有内容的树形图:所有分支、所有存储都触手可及...


        扩展 super-useful answer from SicoAnimal,因此您不必输入所有这些内容(对于没有任何 Git UI 的远程 SSH 会话尤其有用).. .


        1.设置 git 别名:

        # Short and sweet: hashes and graph with all branches and stashes
        git config --global alias.l \
            '!sh -c '"'"' git log --oneline --graph --all --decorate $(git reflog show --format="%h" stash --) '"'"' '
        
        # Same as above + dates and emails
        git config --global alias.ll \
            '!sh -c '"'"' git log --graph --all --date=format:"'"%Y-%m-%d %H:%M"'" --pretty=format:"'"%C(yellow)%h%Creset%C(auto)%d%Creset %C(cyan)%cd%Creset %s %C(green)(%ce)%Creset"'" $(git reflog show --format="%h" stash --) '"'"' '
        

        2。使用别名:

        # Short and sweet: hashes and graph with all branches and stashes
        git l
        
        # Same as above + dates and emails
        git ll
        

        3.甜蜜的结果

        请注意,您可以看到所有存储,而不仅仅是给定提交中的最新存储(用箭头显示)。


        改进空间:

        # In case there are no stashes you get one-liner error message.
        # The rest works as expected. Not sure how to fix it.
        me@mymachine:~/projects/experiment/latest-angular-ten$ git l
        fatal: bad revision 'stash'
        * 00a696b (HEAD -> master) initial commit
        
        

        参考资料:

        How to create a Git alias with nested commands with parameters?

        【讨论】:

          【解决方案7】:

          如果您负担得起图形 GUI,请查看 gitk

          它以一种视觉上不吸引人但非常紧凑和有用的形式向您显示分支、标签、远程分支存储等。它通常与包管理器中的“git”包一起提供,如果你也有“tk”(它使用的 GUI 工具包),它也可以工作。

          【讨论】:

          • 默认情况下只显示最顶层的存储。如果你有办法让它展示更多,我很想听听。
          猜你喜欢
          • 1970-01-01
          • 2020-06-01
          • 2021-04-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-06-05
          • 2022-08-03
          • 2017-05-07
          相关资源
          最近更新 更多