[英]How to revert and go the previous stage before commit
I am new at version control system (git).我是版本控制系统 (git) 的新手。 I did a mistake and when I realize it happen its too late.
我犯了一个错误,当我意识到它发生时为时已晚。 what I did
我做了什么
(1) commit current work
(2) git pull --rebase origin master
Then I go to a previous commit using然后我使用
(3) git checkout 858223adcac47288c44c4c07fbc3938773d778b8
Now I need to go the previous stage(1) before committed.现在我需要在提交之前进入上一个阶段(1)。 And I really don't know how to go there.
我真的不知道怎么去那里。 That's mean I want to go my master and undo the rebase .
这意味着我想去我的主人并撤消 rebase 。
I heartily thank if anyone tell me how to do this.如果有人告诉我如何做到这一点,我衷心感谢。
git
saves history of refs
(read branches
) mostly for this kind of scenarios when you want a commit that is no longer reachable from any of the current refs
. git
保存refs
历史记录(读取branches
)主要用于这种情况,当您想要一个不再可以从任何当前refs
访问的提交时。
Unless enough time passed or you explicitly made reflog
entries expire and garbage collect, the history is available by issuing git reflog <branch>
outputting changes to branch to in form of <sha> <action description leading to changing value of branch>
starting with most recent one.除非经过足够的时间或您明确地使
reflog
条目过期并进行垃圾收集,否则历史记录可通过发出git reflog <branch>
以<sha> <action description leading to changing value of branch>
形式输出对分支的更改<sha> <action description leading to changing value of branch>
从最开始最近的一个。
Find the one you want to get back to (probably one that was prior to the commit you mentioned), examining:找到您想要返回的那个(可能是您提到的提交之前的那个),检查:
git reflog master
Check it out to double check the contents:检查它以仔细检查内容:
git checkout <sha>
Move to master and reset
master to that commit (caution that hard reset
is potentially dangerous/troublesome if used incorrectly):移动到 master 并将 master
reset
为该提交(注意,如果使用不当, hard reset
有潜在危险/麻烦):
git checkout master
git reset --hard <sha>
Some notes:一些注意事项:
How git-rebase
works. git-rebase
如何工作。 This will help to understand how no longer reachable
can arise during rebase
https://git-scm.com/book/en/v2/Git-Branching-Rebasing这将有助于了解在
rebase
https://git-scm.com/book/en/v2/Git-Branching-Rebasing期间如何no longer reachable
It's also possible to create another commit on top of rebased
commit that effectively undoes the pulled part, but that's less practical and noted for completeness only.它也可以创建另一个承诺之上
rebased
犯,有效地撤销被拉伸的部分,但是这不太实用且仅用于完整性指出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.