[英]Cancel git merge after git commit
I made some changes on my branch, I fetched changes and ran 'git merge'.我在我的分支上做了一些更改,我获取了更改并运行了“git merge”。 I then made more local changes and wanted to amend my commit: git commit --amend.
然后我做了更多本地更改并想修改我的提交:git commit --amend。 But when trying to push I received that error:
但是在尝试推送时我收到了该错误:
remote: error: GH006: Protected branch update failed for refs/heads/v1.
remote: error: This branch must not contain merge commits.
! [remote rejected] v1 -> v1 (protected branch hook declined)
error: failed to push some refs to xxx
I tried to abort but:我试图中止但是:
git merge --abort
fatal: There is no merge to abort (MERGE_HEAD missing).
How can I cancel the merge commit without losing my local changes?如何在不丢失本地更改的情况下取消合并提交?
I was able to cancel the merge by cancelling the commit, and to keep my local changes by doing:我能够通过取消提交来取消合并,并通过执行以下操作来保留我的本地更改:
git reset --soft HEAD~1
I would recommend creating a new branch because the following steps could delete some of your changes permanently.我建议创建一个新分支,因为以下步骤可能会永久删除您的一些更改。 Also create a backup of your directory just in case.
还要为您的目录创建一个备份以防万一。
First checkout a new branch from your current one, eg git checkout -b my-new-branch
.首先从当前分支签出一个新分支,例如
git checkout -b my-new-branch
。
Then hard set your branch to your last commit on your branch before you merged in the other branch: git reset --hard <last commit reference, eg 134124124124>
.然后将您的分支硬设置为您在合并到另一个分支之前在您的分支上的最后一次提交:
git reset --hard <last commit reference, eg 134124124124>
。
Then you could cherry pick any commits you made on your old branch after the merge commit, eg git cherry-pick 123123123
.然后你可以在合并提交后挑选你在旧分支上所做的任何提交,例如
git cherry-pick 123123123
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.