简体   繁体   English

如何撤消尚未推送的提交?

[英]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.

相关问题 如何查看尚未推送的提交列表? - How do I view the list of commits that haven't been pushed yet? Git:如何确保不将哈希提交/推入尚未推送到远程的子模块? - Git: how do I make sure I don't commit/push hashes to submodules which haven't been pushed to remote yet? 如何修复我的本地存储库,以便我可以保存尚未推送到主 git 存储库的提交的工作? - How do I fix my local repo so I can save work from commits that haven’t been pushed to the master git repo? 撤消git merge(尚未推送) - Undo a git merge (hasn't been pushed yet) 撤消尚未推送的 Git 合并 - Undo a Git merge that hasn't been pushed yet 如何撤消已推送到远程服务器的 git 中的多个提交? - How to undo multiple commits in git that have been pushed to a remote server? 当我还没有推送时,如何对旧提交进行一些小的修复? - How to make a small fix of an old commit when I haven't pushed yet? 什么是git命令来删除尚未推送到远程的不需要的提交? - What is the git commands to delete unwanted commits that haven't been pushed to the remote? 如何使用 git 撤消推送的提交? - How can I undo pushed commits using git? 如何撤消已经推送到源的git reword? - How do I undo a git reword that's already been pushed to origin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM