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!
Unlike: How to undo last commit(s) in Git?
I want to go back "N" number of commits.
DESCRIPTION. This command uses a binary search algorithm to find which commit in your project's history introduced a bug. You use it by first telling it a "bad" commit that is known to contain the bug, and a "good" commit that is known to be before the bug was introduced.
If you want to look at previous commits, you can use git log and its many arguments. If you want to checkout an actual commit to view the files in an editor, just use git checkout to move to any commit you want. When you are finished, just do git checkout master to return to your current state.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With