git 使用 sourcetree 将推送恢复到远程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26590145/
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
Reverting push to remote with sourcetree
提问by Michael Kloet
I accidently pushed a feature branch to the remote master. Now I want to revert the master to the previous commit. When I select 'Revert current branch to this commit' only the local branch is reverted, and because the remote master is 55 ahead (accidental push) I cannot push the just reverted local master to the remote.
我不小心将一个功能分支推送到远程主服务器。现在我想将 master 恢复到之前的提交。当我选择 'Revert current branch to this commit' 时,只有本地分支被恢复,并且因为远程 master 领先 55(意外推送)我无法将刚刚恢复的本地 master 推送到远程。
When looking into this issue on SO and Google, I found that many people use force push using the command line. But since I'm using Source Tree I'd like to come up with a way that actually uses Source Tree.
在 SO 和 Google 上查看此问题时,我发现许多人使用命令行强制推送。但是由于我使用的是 Source Tree,所以我想提出一种实际使用 Source Tree 的方法。
I also found the rebase option, but I can't seem to find a step-by-step tutorial..
我还找到了 rebase 选项,但我似乎找不到分步教程..
Any ideas?
有任何想法吗?
回答by Jesús Carrera
When you push a commit, the safest way to revert it (rather than forcing the push with -f) is to use the revert
function, so a new commit is created on top of your previous commit.
当您推送提交时,还原它的最安全方法(而不是使用 -f 强制推送)是使用该revert
函数,因此会在您之前的提交之上创建一个新的提交。
This is possible to do using Sourcetree, right clicking in the commit that you want to revert, and selecting "Reverse commit...".
这可以使用 Sourcetree 来完成,右键单击要还原的提交,然后选择“反向提交...”。
You would need to do this for each commit you want to revert, in reverse order.
您需要以相反的顺序对要还原的每个提交执行此操作。
回答by LearnerAllTheWay
The best way to do this is with Reset <branch> to this commit
option shown in the image below.
最好的方法是使用下Reset <branch> to this commit
图所示的选项。
A pop up will be displayed to you to choose what mode of code reset you would like to choose. [See below]
将向您显示一个弹出窗口,以选择您要选择的代码重置模式。[见下文]
Note:This is not exactly code reversal, but it removes your commit entirely from the local and makes it look cleaner.
注意:这并不完全是代码反转,但它会完全从本地删除您的提交并使其看起来更干净。
回答by eckes
Sourcetree doesn't expose the -f
flag to you: https://answers.atlassian.com/questions/54469/how-do-i-perform-a-forced-push-push-f-from-sourcetree
Sourcetree 不会-f
向您公开该标志:https: //answers.atlassian.com/questions/54469/how-do-i-perform-a-forced-push-push-f-from-sourcetree
So, the only way to bring the remote back to it's original state is to git revert
each commit you introduced in the reverse order.
因此,将遥控器恢复到其原始状态的唯一方法git revert
是以相反顺序引入的每个提交。
Assuming the remote was on commit A
and you pushed your feature branch holding commits B
, C
and D
, you have to
假设远程正在提交A
并且您推送了持有提交的功能分支B
,C
并且D
,您必须
git revert D
git revert C
git revert B
git push
The push will work fine since you're not modifying the pushed history but instead push a new set of changes.
推送会正常工作,因为您没有修改推送的历史记录,而是推送一组新的更改。
If you want to shorten your series of reverts to one commit, you could do a
如果您想将一系列还原缩短为一次提交,您可以执行以下操作
git rebase -i origin/master
and select each of your revert
commits to be squashed
. Then, your push
will only contain one commit that reverts D
, C
and B
in one go.
并选择您的每个revert
提交为squashed
. 然后,您的push
遗嘱将只包含一次恢复的提交D
,C
并且B
一次性完成。