在上次提交时执行代码,而不用硬重置最新的提交 [英] Execute code on the previous commit without hard resetting the latest commit

查看:117
本文介绍了在上次提交时执行代码,而不用硬重置最新的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图验证我的更改没有破坏现有的代码。要做到这一点,在提交我的更改后,我运行代码,并且需要用前一个提交(它没有我的更改)验证输出。所以,在验证完成之后,我的更改仍然必须在最新的提交中。

I am trying to validate that my changes aren't breaking existing code. To do that, after committing my changes I run the code and I need to validate the output with one previous commit(which does not have my changes). So, after the validation is done my changes must still be on the latest commit.

推荐答案

最简单的方法是只检出分离HEAD状态中的前一个提交:

The easiest way to go here is probably to just checkout the previous commit in the detached HEAD state:

git checkout HEAD~1

您应该看到如下信息:

You should see a message something like this:


您处于'分离的HEAD'状态...

You are in 'detached HEAD' state...

从这一点,您可以构建您的项目并对其进行测试。当你想回到分支的HEAD时,很容易做到这一点:

From this point, you may build your project, and test it. And when you want to go back to the HEAD of the branch, it is easy to do that:

git checkout master      # or replace 'master' by the branch name

这篇关于在上次提交时执行代码,而不用硬重置最新的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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