Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy part of a commit diff in GitHub without the pluses and the minuses?

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.

like image 243
James Ko Avatar asked Aug 17 '17 04:08

James Ko


Video Answer


1 Answers

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:

  • curl the diff itself from GitHub (without cloning the all repo history):

    https://github.com/foo/bar/commit/${SHA}.patch
    
  • pipe it to a sed to remove the +/-:

    .... | sed -r "s/^([^-+ ]*)[-+ ]/\\1/" | less -r
    
like image 135
VonC Avatar answered Nov 15 '22 20:11

VonC