简体   繁体   English

如何在特定提交之前git checkout一次提交

[英]How do I git checkout one commit prior to a specific commit

在经历了github问题之后,我发现了一个可能导致破坏代码的提交,我想通过执行以下操作来确认这种怀疑:

git checkout --one-prior f1962b3cc771184a471e1350fa280d80d5fdd09d

Here you go: 干得好:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^

Notice the ^ at the end. 注意结尾的^ That means one revision behind. 这意味着一个修订背后。

For example this would be 5 revisions behind: 例如,这将是5个版本:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^^^^^

... equivalent to: ... 相当于:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d~5

Btw, when you do this, you'll be in a detached HEAD state. 顺便说一句,当你这样做时,你将处于一个独立的HEAD状态。 The output explains this, which is very interesting and worth reading: 输出解释了这一点,非常有趣,值得一读:

You are in 'detached HEAD' state. 你处于“独立的HEAD”状态。 You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. 您可以环顾四周,进行实验性更改并提交它们,并且您可以放弃在此状态下进行的任何提交,而不会通过执行另一次检出来影响任何分支。

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. 如果要创建新分支以保留您创建的提交,可以再次使用-b和checkout命令(现在或稍后)。 Example: 例:

  git checkout -b new_branch_name 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM