Copying SHA-1 hashes from gitk to the clipboard

7 August 2014, by

I don’t know if anyone else has this problem, but gitk with cygwin gives me the following headache all the time: I can’t copy more than one SHA-1 hash from it to the clipboard.

The problem

Say you want to diff between two commits, or cherry pick a range or something. Find the first commit, select the hash (like other cygwin/unix tools, selecting is enough to copy, so there’s no need to mash ctrl-c), paste it into the command line or wherever you want it.

Why won’t it copy?

So far so good. You needed two commits to diff between, so you select the other commit, select the SHA1 hash, paste it… and it pasted the first one. Even though you copied a new hash. The clipboard hasn’t updated, no matter how much you frantically click on the commit, the hash, select all or part of the text.


Of course you could just close gitk and open it again, but there’s a slightly quicker way.

After years of suffering, I finally googled it and found this comment on a cygwin-X bug report: (Cygwin-X is the thing which allows these unix GUI tools to render in Windows.) Apparently gitk isn’t telling cygwin-X when the text in that field changes. The clipboard will only notice the new hash value if you point it at a different control (any other part of gitk should do), then back again.

So the trick is: copy some random text from a different field in gitk, then copy the hash you want from the SHA-1 field.

Select any old text first, just to copy something into the clipboard from a different field

Tags: ,

Categories: Technical


2 Responses to “Copying SHA-1 hashes from gitk to the clipboard”

  1. olek says:

    you’re a genius, thx!

  2. Joeri says:

    This did not work for me, but it does in a slightly different way.
    I run Ubuntu in a virtual box, if I first copy a text in Notepadd ++ in windows for example and then the SHA1 in Ubuntu gitk and then a text in notepadd ++ and then gitk again.
    Then it works for me.

Leave a Reply

* Mandatory fields

3 × = eighteen

Submit Comment