簡體   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