Go back N commits to Git to find a commit that triggers test regressions

Is there a command that allows me to check a commit based on its distance from the current commit instead of using commit identifiers?

Usage example

Basically, I am thinking of setting up the cron script job type to do the following on the build server:

  • Pull out the last of the git branches (git pull dev).
  • Build it, run the tests.
  • If the percentage of skips is lower than the last saved percentage:
    • Recursively commit, build, and run tests until you find a commit where the percentage has changed.
    • Record commits by entering regressions.

I have a general idea of ​​how this will depend together, but this will not work if I cannot periodically return a single commit.

If there is no specific command, I suggest that I could grep the commit log and take the first one each time?

I appreciate any ideas or help!

Unlike: How to undo the last commit in Git?

I want to return "N" the number of commits.

+7
source share
2 answers
git checkout HEAD~N 

will check the Nth commit before your current commit.

If you have mergers in your story, you may be interested in

 git checkout HEAD^N 

which will check the Nth merge parent (most merge transactions have 2 parents).

So, to always return a single commit after the first parent of any commit:

 git checkout HEAD^1 

You may also be interested in git bisect - Find the change that introduced the error by binary search.

+16
source

Iterating over each commit and running tests can be really ineffective if the number of commits is much larger than the number of commits that introduce errors. There is no need to run tests against every commit in history to find the one that introduced the error! You really should watch git bisect , especially git bisect run .

The question indicates that you want to find every commit that introduced an error from some point in history, and not just from a recently entered one. I don't think you can do this with a single git bisect call; you will have to put it in a loop in a small script.

+6
source

All Articles