I use the following script to autotag the current workspace while building even if there are changed (not committed) files:
#!/bin/bash tagname="autobuild-test1" commitname="autocommit for tag $tagname" set -e head="`git rev-parse HEAD`" test -n "$head" git commit -m "$commitname" -a taghead="`git rev-parse HEAD`" git tag "$tagname" "$taghead" #or just `git tag "$tagname" HEAD` for the 2 lines above git reset "$head"
The idea: I commit everything which is not committed to a 'temporary commit' and tag its hash. After doing this, I revert to the original state by resetting to the previous HEAD.
In other words: I try to do
git commit -a without touching HEAD, staging, stashing and workspace.
- this also works if the workspace is dirty
- the script is very flexible
- the script doesn't touch any files, doesn't do any checkout or remove operations
- the staging state is completely cleared after running the script
- probably more state modifications which I didn't find yet
- it is a script. I would prefer a single command for this use case
- no proper error handling. if the script fails, HEAD might be changed
This script was inspired by cvs2git which uses the same strategy in cases where it's not clear to which revision a tag belongs to.
Is there anything you would change to make this script more rubust and/or to remove some of the cons?