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

标签 git

在浏览了 github 问题后,我发现了一个可能导致破坏代码的提交,我想通过执行以下操作来确认这种怀疑:
git checkout --one-prior f1962b3cc771184a471e1350fa280d80d5fdd09d

最佳答案

干得好:

git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^

请注意 ^在末尾。这意味着落后一个修订版。

例如,这将落后 5 个修订版:
git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d^^^^^

... 相当于:
git checkout f1962b3cc771184a471e1350fa280d80d5fdd09d~5

顺便说一句,当您这样做时,您将处于分离的 HEAD 状态。输出解释了这一点,非常有趣,值得一读:

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

关于git - 如何在特定提交之前 git checkout 一次提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20455980/

相关文章:

git - 你应该 fork 你自己的项目并提交 pull 请求吗?

git - 如何为任何命令制作 git 输出用法?

Git,如何删除路径中带有有趣字符的文件?

git 如何将代码推送到github中的子模块

git - 如何将标签推送到 CI 中的分支?

php - 使用 composer 开发库的最佳方式是什么?

git - 我可以恢复在交互式 rebase 期间丢失的提交吗?

git - 在 Git 中,我怎样才能看到从 master 到 develop 的差异?

git - 为什么没有 git commit -A -m ?肯定是故意省略的,但是为什么呢?

仅偶尔提交输出文件的 Git 工作流程