Is there a command that will let me checkout a commit based on its distance from the current commit instead of using commit IDs?
Basically I am thinking of setting up a cron job type script to do the following on a build server:
I have a rough idea for how this would hinge together but it won't work unless I can go back one commit periodically.
If there is no specific command I suppose I could grep the commit log and take the first one each time?
I appreciate any ideas or help!
How to undo last commit(s) in Git?
I want to go back "N" number of commits.
git checkout HEAD~N
will checkout the Nth commit before your current commit.
If you have merge commits in your history, you may be interested in
git checkout HEAD^N
which will checkout the Nth parent of a merge commit (most merge commits have 2 parents).
So, to always go back one commit following the first parent of any merge commits:
git checkout HEAD^1
You may also be interested in
git bisect - Find by binary search the change that introduced a bug.
Iterating over each commit and running the tests could be really inefficient if the number of commits is much larger than the number of commits that introduce errors. There's no need to run the tests against every commit in the history, to find the one that introduced the error! You really should look at
git bisect, particularly
git bisect run.
The question indicates you want to find every commit that introduced an error since some point in history, not just the most recently introduced one. I don't think you can do that with one invocation of
git bisect; you'll have to put it in a loop in a small script.