Last active
August 29, 2015 14:06
-
-
Save codyromano/f900de0afffcf75de289 to your computer and use it in GitHub Desktop.
Get the hash for the HEAD of your branch in 12 lines of code. Purely client-side; no dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current hash for master: <span id="currentHash"></span> | |
<script> | |
/** | |
* This displays the commit hash for the HEAD of your chosen Git branch. | |
* It helps you stay on the same page with other team members during | |
* development. If their hash matches yours, your branches are in the same state. | |
* | |
* This is useful for web projects that don't follow a standard versioning process. | |
* If you have an automated process for keeping track of versions, this code may | |
* complement it. | |
* | |
* @param {String} branch The Git branch you care about (e.g. master or develop) | |
* @param {Object} el DOM element where the result should be displayed. | |
*/ | |
(function (branch, el) { | |
var xmlRequestObj = new XMLHttpRequest; | |
xmlRequestObj.onreadystatechange = function () { | |
if (xmlRequestObj.readyState == 4) { | |
window.addEventListener('load', function () { | |
el.innerHTML = xmlRequestObj.responseText.slice(0, 10); | |
}, false); | |
} | |
}; | |
xmlRequestObj.open('GET', '.git/refs/heads/' + branch); | |
xmlRequestObj.send(); | |
})('master', document.getElementById('currentHash')); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment