[英]Take sha number of commit by tig
Check if the command proposed in jonas/tig
issue 557 would work for you: 检查在
jonas/tig
问题557中建议的命令是否对您jonas/tig
:
bind generic 9 !sh -c "echo -n %(commit) | xclip -selection c && echo Copied %(commit) to clipboard"
That would copy the current commit SHA1 in your clipboard. 这将在剪贴板中复制当前提交SHA1 。
In the Wiki binding page , you also have example for Mac or Cygwin: 在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
The OP megas proposes in the comments to use git rev-parse
: 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"
Or, to copy the short sha-1:或者,复制简短的 sha-1:
bind generic 9 !@sh -c "printf '%s' $(git rev-parse --short %(commit)) | pbcopy"
Inspiration source: /tig/doc/tigrc(5) - Bind Command in the exemple section.灵感来源: /tig/doc/tigrc(5) - 示例部分中的绑定命令。
Solutions listed in VonC 's answer did not work for me because of a return line in the pasted result (⌘+V). VonC的答案中列出的解决方案对我不起作用,因为粘贴的结果中有返回行 (⌘+V)。 So I was not able to type such command in tig
:!git rebase -i [paste_here_hitting_⌘+V]~
所以我无法在
:!git rebase -i [paste_here_hitting_⌘+V]~
输入这样的命令:!git rebase -i [paste_here_hitting_⌘+V]~
To copy the short SHA1 on MacOS (can be easily adapted to other OS):在MacOS上复制短 SHA1(可以轻松适应其他操作系统):
bind generic 9 +@sh -c "printf '%s' $(git rev-parse --short %(commit)) | pbcopy && echo Copied %(commit) to clipboard"
As an improvement to other answers, this version prints out a message to the status bar which is nicer to closing the tig
UI or having nothing printed out.作为对其他答案的改进,此版本会向状态栏打印一条消息,这对于关闭
tig
UI 或不打印任何内容更好。 The +
option flag enables to do so ( source ). +
选项标志可以这样做( source )。 Also no extra newline character at the end like VonC 's answer.最后也没有像VonC的回答那样额外的换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.