简体   繁体   中英

Take sha number of commit by tig

I love to use tig client to navigate through git commits.

But I'm missing one thing for now.

Is there a key binding to take a sha number of a git commit I'm currently staying at?

Check if the command proposed in jonas/tig issue 557 would work for you:

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.

In the Wiki binding page , you also have example for Mac or 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 :

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

MacOS

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

Or, to copy the short 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.

Solutions listed in VonC 's answer did not work for me because of a return line in the pasted result (⌘+V). So I was not able to type such command in tig :!git rebase -i [paste_here_hitting_⌘+V]~

To copy the short SHA1 on MacOS (can be easily adapted to other OS):

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. The + option flag enables to do so ( source ). Also no extra newline character at the end like VonC 's answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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