11

It's very often that I need to copy-and-paste part of a GitHub commit. Whenever I do this, however, I find myself manually going down each line and hitting Delete to strip all of the +/- signs.

Is there a more convenient way to copy part of a GitHub commit to the clipboard?
Suggestions involving Chrome extensions/your personal projects are welcome.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
James Ko
  • 32,215
  • 30
  • 128
  • 239

1 Answers1

8

Update July 2018:

Unselectable diff markers

The + and - diff markers are no longer copied to your clipboard when you copy the contents of a diff.

Yay!


Original answer (August 2017)

You could:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    but, but... I *want* the diff markers! Often I copy a diff from the terminal and paste it, with markers, into markdown doc, with the `diff` code fence tag, so it gets syntax highlighted (e.g. in green and red). I just tried to do this with a diff from github, found that I couldn't, had to *add* the markers manually, did a bit of googling and found that copy used to include the markers, but now doesn't - waaah! :) – drkvogel May 28 '20 at 22:41
  • @drkvogel So why not copy it from the patch URL I mentioned originally? (example: https://github.com/git-for-windows/git/commit/01c50adf56430fdd98f903691ae41a83870801c0.patch): the +/- are there. – VonC May 29 '20 at 05:05
  • OK, that's a good workaround, thanks. Not obvious, though, unless you have seen this thread and followed your links (which I now have). Perhaps GitHub should show a link to the patch, even though it's as simple as adding `.patch` to the URL? – drkvogel May 31 '20 at 11:35
  • @drkvogel Agreed: that feature could benefit from more visibility in the UI. – VonC May 31 '20 at 19:20