Created
February 26, 2013 03:14
-
-
Save garrow/5035571 to your computer and use it in GitHub Desktop.
A very simple git pre-commit hook to add/set a VERSION file with each commit. It will automatically insert the version and add that to the pending commit. Note that git hooks are not distributed with the repo, though adding to a fresh repo via the dev environment bootstrap script for our project works fine.
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
~/work/tmp/version_file <master +>± git status | |
# On branch master | |
# Changes to be committed: | |
# (use "git reset HEAD <file>..." to unstage) | |
# | |
# new file: foo | |
# | |
~/work/tmp/version_file <master +>± git diff --staged | |
diff --git a/foo b/foo | |
new file mode 100644 | |
index 0000000..88bf918 | |
--- /dev/null | |
+++ b/foo | |
@@ -0,0 +1 @@ | |
+touched foo | |
~/work/tmp/version_file <master +>± git commit -m "touched ./foo" | |
[master 2e6a2d2] touched ./foo | |
2 files changed, 2 insertions(+), 1 deletion(-) | |
create mode 100644 foo | |
~/work/tmp/version_file <master>± git show | |
commit 2e6a2d2f13bb8c4ed321b90d8b591acf9116aecd | |
Author: Garrow Bedrossian <garrow.bedrossian@hitwise.com> | |
Date: Tue Feb 26 14:06:43 2013 +1100 | |
touched ./foo | |
diff --git a/VERSION b/VERSION | |
index ec213cf..d0e6678 100644 | |
--- a/VERSION | |
+++ b/VERSION | |
@@ -1 +1 @@ | |
-v0.1-1-g4584f85 | |
+v0.1-2-g4fcc0c7 | |
diff --git a/foo b/foo | |
new file mode 100644 | |
index 0000000..88bf918 | |
--- /dev/null | |
+++ b/foo | |
@@ -0,0 +1 @@ | |
+touched foo |
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
#!/bin/sh | |
# Filename is actually: .git/hooks/pre-commit | |
git describe > VERSION | |
git add VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment