Go back N commits in Git to find commit that causes test regressions

自古美人都是妖i 提交于 2019-12-04 00:24:40
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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!