So here's the scenario. I've got a script that runs some tests. I need to make another script that accepts as a parameter a git commit name and then does the following:
- Switches to a detached HEAD at the specified commit
- Runs the test script against that commit
- Switches back so HEAD is the same as it was before this business
I need to make sure this script is robust so that it's never destructive no matter the state of the repository. It should work when it's run from a detached HEAD or from a regular branch, and preferably it should work even when there are uncommitted or unstaged changes around.
I feel like this should be an easy question to answer, since running a test script against a previous commit seems like a really common task to want to automate. But I can't seem to find any simple series of commands to do it.