Git 恢复失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13929526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:06:32  来源:igfitidea点击:

Git revert failed

gitgit-commitgit-revert

提问by epsilones

I made several commits (commit1/2/3), I changed my working directory without stashing. Then I wanted to go back several commits ago. So I git revert commit1 commit2 commit3, but I was told to commit my changes (commit4), so I did it, and then I made again git revert commit1 commit2 commit3 commit4, but I had a message

我做了几次提交(commit1/2/3),我改变了我的工作目录而没有隐藏。然后我想回到几个提交前。所以我 git revert commit1 commit2 commit3,但我被告知要提交我的更改(commit4),所以我做了,然后我再次 git revert commit1 commit2 commit3 commit4,但我有一条消息

error: a cherry-pick or revert is already in progress hint: try "git cherry-pick (--continue | --quit | --abort)"

错误:樱桃挑选或还原已经在进行中提示:尝试“git cherry-pick (--continue | --quit | --abort)”

When I run git branch -va, HEAD is pointing to commit 3

当我运行 git branch -va 时,HEAD 指向 commit 3

I don't quite understand what is going on. What should I do now to make things reverted?

我不太明白这是怎么回事。我现在该怎么做才能让事情恢复原状?

回答by VonC

It is best to initiate a revert with a clean index and working tree.
Otherwise, doing a second revert (on top of a new commit) while a previous revert was in progress leads to that error message.

最好使用干净的索引和工作树启动恢复。
否则,在先前的还原正在进行时进行第二次还原(在新提交之上)会导致该错误消息。

Since you are still at commit 3, you could:

由于您仍在commit 3,您可以:

  • git cherry-pick --quit(which, from this thread, tells revert to leave HEADalone and get out of the way.),
  • examine your index and working tree (git status),
  • make any adjustment to get a clean status (like a new commit),
  • and then re-do your git revert.
  • git cherry-pick --quit(从这个线程中,告诉 revertHEAD独自离开并让开。),
  • 检查您的索引和工作树(git status),
  • 进行任何调整以获得干净的状态(如新提交),
  • 然后重新做你的git revert.

(you can see other options at "Rollback to Previous Commit - Github for MAC (a revert is already in progress)")

(您可以在“回滚到上一次提交 - Github for MAC(还原已在进行中)”中看到其他选项)

Don't forget git resetif you simply want to forget about those three commits (although that would make you force a push: git push --force, in order to publish your history for that branch. If other collaborators already pulled from that same branch, your approach, using git revert, is a better one)

不要忘记,git reset如果您只是想忘记这三个提交(尽管这会让您强制 push: git push --force,以便发布该分支的历史记录。如果其他合作者已经从同一分支中提取,您的方法,使用git revert,是一个更好的)