回滚到上一个提交 - Github的MAC(恢复已在进行中) [英] Rollback to Previous Commit - Github for MAC (a revert is already in progress)

查看:2121
本文介绍了回滚到上一个提交 - Github的MAC(恢复已在进行中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对上次提交的代码进行了一些更改,添加了新的功能,并意识到其他一些代码现在表现得很奇怪。我决定回滚一个旧的提交(推送到远程)以测试该功能是否正常工作。



在我按下Rollback之前,我承诺我目前所做的更改是因为我不想失去它们。提交后(不推送到远程),我做了回滚到那个旧的提交。 (请注意,在我提交的提交和刚刚提交的提交之间有不少提交)。

一切正常,我的代码恢复为提交。这个提交中的功能也有问题,所以我决定回到最近的提交中。

然而,我不知道如何去做,除了回滚到最新的提交。但它给了我一个错误。

 错误:樱桃挑选或还原已在进行中
提示:尝试git cherry-pick(--continue | --quit | --abort)
致命:恢复失败
(32768)

现在,似乎大部分事情都回来了,但当前版本的代码与我上次提交的代码不同。它介于两者之间。 =(



我做错了什么?[我没有问出无罪,我知道我做错了;]]

正确的做法是什么? [我想我应该先分支]

解决方案

我不知道什么github为Mac回滚做,但似乎你使用命令行解决手头问题会更好:

git cherry-pick --abort - 停止正在进行的樱桃采摘

git branch -va - 会告诉你现在你的指针在哪里

确保你的工作目录是干净的:
git status - 不应该显示任何修改或上演文件

git藏匿 - 如果有任何修改仍然存在

< git reset --hard your_local_branch github / remote_branch - 让本地分支反映远程端的状态。显然你不需要重置,如果你的当前分支将指向与远程相同的提交。如果你处于分离HEAD状态(git状态会告诉你这个状态),那么返回到正常状态只需签出你的本地分支。



现在决定你实际上想实现:



我。摆脱错误的提交?



使用交互式rebase并删除错误提交的行,然后强制推送到github上的远程仓库(比如说在提交之前发生的错误提交10次)

git rebase -i HEAD〜11



恢复错误的提交? - 除非您确定以下提交没有触及相同的代码段,否则不会在其他提交后推荐这样做。这将有效地创建一个反向提交(如果行是由错误的提交添加的,它将通过回复被删除,反之亦然)

git revert {commit -sha1}



三。修改错误的提交?使用交互式分配,但指示它停止错误提交修改。当它停止编辑更改并继续重新绑定时,然后强制推送到远程分支(使用解决方案I中的rebase命令)



完成之后隐藏的使用 git stash pop 将变化带回去。



希望有所帮助!


I think I've messed up here.

I made a few changes to my code from a last commit adding new functionalities and realized that some other piece of code was now acting strangely. I decided to Roll back to an old commit (pushed to remote as well) in order to test if that functionality was working by then.

Before I pressed Rollback, I committed my currently made changes because I did not want to lose them. After committing (not pushing to remote), I did the rollback to that old commit. (note that there were quite a few commits inbetween the commit i roll backed to and the one i committed just now).

All worked fine and my code reverted to that commit. The functionality was misbehaving there in that commit as well so I decided to come back to my most recent commit.

However, I knew not how to do that except Rolling Back to the latest commit. But it gave me an error.

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

Now, it seems like most of things are back but the current version of code isn't the same as my last commit. It is somewhere in between. =(

What did I do wrong? [I'm not asking out of innocence, I know I did it wrong ;)]

What was the right way of doing it? [I think I should have branched first]

解决方案

I do not know what github for Mac rollback does, but it seems that you would be better off using command line to resolve the issue at hand:

git cherry-pick --abort - to stop any cherry-picking in progress

git branch -va - will show you where are your pointers right now

make sure your working directory is clean: git status - should not show any modified or staged files

git stash - if anything modified still present

git reset --hard your_local_branch github/remote_branch - make local branch reflect the state as it is on the remote side. obviously you don't need to do a reset if your current branch will point to the same commit as the remote. If you're in detached HEAD state (git status will tell you about it) then to come back to the normal state just checkout your local branch.

Now decide what you actually want to achieve:

I. get rid of the faulty commit?

Use interactive rebase and remove the line with faulty commit, then force push to the remote repo on github (say faulty commit happened 10 commits ago)

git rebase -i HEAD~11

II. revert faulty commit? - wouldn't recommend to do that after some other commits, unless you're absolutely sure that the following commits didn't touch the same piece of code. This will effectively create a reverse commit (if line was added by faulty commit it will be removed by revert and vice versa)

git revert {commit-sha1}

III. Amend faulty commit? use interactive rebase, but instruct it to stop at faulty commit for amending. When it does stop edit the change and continue rebasing, then force push to the remote branch (use rebase command from the solution I )

After you're done if anything was stashed use git stash pop to bring the changes back.

hope that helps!

这篇关于回滚到上一个提交 - Github的MAC(恢复已在进行中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆