- Create a new bookmark in your bookmarks bar with the following contents:
javascript: (function(){
let location = window.location.href;
let validatorRegex = /https:\/\/github.com\/[a-z][a-zA-z0-9\-\_]+\/[a-z][a-zA-z0-9\-\_]+\/commit\/[a-f0-9]+/g;
let match = location.match(validatorRegex);
if(!match){
console.log('No match. You must be viewing a commit.');
alert('Use this bookmarklet when viewing a commit.');
}
else{
console.log('Location matches a commit - redirecting to diff view.');
let repoLocationRegex = /https:\/\/github.com\/[a-z][a-zA-z0-9\-\_]+\/[a-z][a-zA-z0-9\-\_]+/g;
let commitRegex = /\/commit\/[a-f0-9]+/g;
let repoLocation = location.match(repoLocationRegex)[0];
let commitId = location.match(commitRegex)[0].slice(8);
console.log(repoLocation);
console.log(commitId);
let compareLocation = `${repoLocation}/compare/${commitId}...master `;
window.location.href = compareLocation;
}})();
- Browse to a commit you wish to compare with its current master branch, and press the bookmarklet.
Thanks, this is useful. I had to change
master
tomain
for it to work.