返回Git中的N次提交以查找导致测试回归的提交 [英] Go back N commits in Git to find commit that causes test regressions

查看:121
本文介绍了返回Git中的N次提交以查找导致测试回归的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一条命令可以让我根据其与当前提交的距离而不是使用提交ID来检出提交?

Is there a command that will let me checkout a commit based on its distance from the current commit instead of using commit IDs?

基本上,我正在考虑设置cron作业类型脚本以在构建服务器上执行以下操作:

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

  • 下拉特定git分支的最新版本(git pull dev).
  • 构建它,运行测试.
  • 如果通过百分比低于上次存储的百分比:
    • 递归地返回一次提交,构建,运行测试,直到找到百分比发生变化的提交.
    • 记录引入回归的提交.
    • Pull down the latest of a specific git branch (git pull dev).
    • Build it, run the tests.
    • If the pass percentage is lower than the last stored percentage:
      • Recursively go back a commit, build, run tests, until it finds the commit where the percentage changed.
      • Log the commits that introduced regressions.

      对于如何将它们铰接在一起,我有一个粗略的想法,但是除非我可以定期回溯一次提交,否则它将无法正常工作.

      I have a rough idea for how this would hinge together but it won't work unless I can go back one commit periodically.

      如果没有特定的命令,我想我可以grep提交日志并每次获取第一个?

      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!

      与以下不同: 如何撤消Git中的最后一次提交?

      我想返回"N"次提交.

      I want to go back "N" number of commits.

      推荐答案

      git checkout HEAD~N
      

      将在当前提交之前检出第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
      

      这将检出合并提交的第N个父级(大多数合并提交有2个父级).

      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
      

      您可能还对git bisect感兴趣-通过二进制搜索查找引入错误的更改.

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

      这篇关于返回Git中的N次提交以查找导致测试回归的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆