繁体   English   中英

获取 tig 提交的 sha 数

[英]Take sha number of commit by tig

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

但我现在缺少一件事。

是否有一个键绑定来获取我目前使用的 git 提交的 sha 号?

检查在jonas/tig问题557中建议的命令是否对您jonas/tig

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

这将在剪贴板中复制当前提交SHA1

Wiki绑定页面中 ,您还拥有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 在评论中建议使用git rev-parse

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

苹果系统

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) - 示例部分中的绑定命令

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

MacOS上复制短 SHA1(可以轻松适应其他操作系统):

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM