Skip to content

Instantly share code, notes, and snippets.

@lmj0011
Last active March 21, 2018 21:48
Show Gist options
  • Save lmj0011/cb37eba76f2eef9cd54ae3c4f7bbb3cf to your computer and use it in GitHub Desktop.
Save lmj0011/cb37eba76f2eef9cd54ae3c4f7bbb3cf to your computer and use it in GitHub Desktop.
Remove Minus and Plus Signs when cherrypicking Github Commits

Open up the web console while viewing the file(s) of a commit on Github and paste in this snippet:

var added_nodes = document.querySelectorAll(".blob-code.blob-code-addition .blob-code-inner");
var deleted_nodes = document.querySelectorAll(".blob-code.blob-code-deletion .blob-code-inner");
// var neutral_nodes = document.querySelectorAll(".blob-code.blob-code-context .blob-code-inner"); //don't think one is necessary
var str, new_str, pieces;

function removeNodes(nodes) {
  for(var i=0;  i < nodes.length;  i++) {
    str = nodes[i].innerHTML;
    
    pieces= str.split('');
    pieces[0] = ' ';

    nodes[i].innerHTML = pieces.join('');
  }
}

removeNodes(added_nodes);
removeNodes(deleted_nodes);
// removeNodes(neutral_nodes);

based from: https://gist.github.com/crookedneighbor/a12148b54315ca92124b

@vinay30
Copy link

vinay30 commented Mar 21, 2018

Could you just do:

var added_nodes = document.querySelectorAll(".blob-code.blob-code-addition .blob-code-inner");
var deleted_nodes = document.querySelectorAll(".blob-code.blob-code-deletion .blob-code-inner");

function removeNodes(nodes) {
  for(var i = 0; i < nodes.length; i++) {
    nodes[i].innerHTML = nodes[i].innerHTML.replace('+', ' ');
  }
}

removeNodes(added_nodes);
removeNodes(deleted_nodes);

Since without the /g flag, replace will just swap out the first instance of +.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment