【问题标题】:Take sha number of commit by tig通过 tig 获取 sha 提交数
【发布时间】:2019-03-03 17:05:03
【问题描述】:

我喜欢使用tig 客户端浏览 git 提交。

但我现在缺少一件事。

是否有一个键绑定来获取我当前停留的 git commit 的 sha 编号?

【问题讨论】:

    标签: git sha tig


    【解决方案1】:

    检查jonas/tig issue 557 中建议的命令是否适合您:

    bind generic 9 !sh -c "echo -n %(commit) | xclip -selection c && echo Copied %(commit) to clipboard"
    

    这将复制剪贴板中的current commit SHA1

    Wiki binding page 中,您还有 Mac 或 Cygwin 的示例:

    bind generic 9 !@sh -c "git show -s --format=%s %(commit) | xclip -selection c" # Linux
    bind generic 9 !@sh -c "git show -s --format=%s %(commit) | pbcopy" # Mac
    bind generic 9 !@sh -c "git show -s --format=%s %(commit) > /dev/clipboard" # Cygwin
    

    OP megas提议in the comments使用git rev-parse

    bind generic 9 !@sh -c "git rev-parse --short %(commit) | pbcopy"
    

    【讨论】:

    • 我想出了这个解决方案:bind generic 9 !@sh -c "git rev-parse --short %(commit) | pbcopy"
    • @megas 好的,我已将您的评论包含在答案中以提高知名度。
    【解决方案2】:

    MacOS上复制短SHA1(可以很容易地适应其他操作系统):

    bind generic 9 +@sh -c "printf '%s' $(git rev-parse --short %(commit)) | pbcopy && echo Copied %(commit) to clipboard"
    

    作为对其他答案的改进,此版本会向状态栏打印一条消息,这对于关闭tig UI 或不打印任何内容更好。 + 选项标志允许这样做 (source)。最后也没有像VonC's answer那样的额外换行符。

    【讨论】:

    • 不错!这似乎是一个不错的选择。赞成。
    【解决方案3】:

    MacOS

    bind generic 9 !@sh -c "printf '%s' %(commit) | pbcopy"
    

    或者,复制短 sha-1:

    bind generic 9 !@sh -c "printf '%s' $(git rev-parse --short %(commit)) | pbcopy"
    

    灵感来源:示例部分中的/tig/doc/tigrc(5) - Bind Command

    VonC 的答案中列出的解决方案对我不起作用,因为粘贴的结果中有回车线 (⌘+V)。所以我无法在 tig :!git rebase -i [paste_here_hitting_⌘+V]~ 中输入这样的命令

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-13
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      相关资源
      最近更新 更多