[英]How do I undo commits that haven't been pushed yet?
I made two commits without pushing them. 我做了两次提交而没有推它们。 There have been multiple other commits pushed to my branch.
已经有多个其他提交被推送到我的分支机构。 I haven't yet pulled those commits.
我还没有撤回这些提交。 I want to destroy my two commits that haven't been pushed, and then just get the multiple other commits that have been pushed by others.
我想要销毁我没有被推送的两个提交,然后只获得其他人推送的其他多个提交。 Can someone help me with this?
有人可以帮我弄这个吗?
I thought to reverse the two commits, one by one. 我想一个接一个地反转这两个提交。 But I want to keep my other changes.
但我想保留其他变化。 Will this work?
这会有用吗?
If you have two commits that you haven't pushed, and you don't want them at all, then rather than reverse then, you should reset to the commit that want to start from and then pull. 如果你有两个你没有推送的提交,而你根本不想要它们,那么你应该重置为想要开始然后拉动的提交,而不是反转。
So, I'm assuming that you have the following situation. 所以,我假设你有以下情况。
$ git log --oneline --graph
* fde0ba4 Commit 2 (don't want)
* d7be6f3 Commit 1 (don't want)
* 7a70e45 Before my new commits (start here!)
* db58591 Even earlier
...
And so on. 等等。 You don't want the first two commits, but you want the the third onwards.
你不希望前两个提交,但你想要第三个提交。 The first step is to reset back to where you want to start from.
第一步是重置回你想要的地方。
git reset --hard 7a70e45
Note that this is a destructive operation -- you'll lose those commits, and the content of those commits, so do this with care! 请注意,这是一种破坏性操作 - 您将丢失这些提交以及这些提交的内容,因此请谨慎操作! See the
git reset
documentation if you're not sure if --hard
is appropriate. 如果您不确定
--hard
是否合适,请参阅git reset
文档 。
After resetting, you should be able to pull without a problem. 重置后,您应该能够毫无问题地完成任务。
git pull
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.