简体   繁体   中英

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:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^^^^^

... equivalent to:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d~5

Btw, when you do this, you'll be in a detached HEAD state. The output explains this, which is very interesting and worth reading:

You are in 'detached HEAD' state. 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. Example:

  git checkout -b new_branch_name 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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