I made some changes on my branch, I fetched changes and ran 'git merge'. I then made more local changes and wanted to amend my commit: 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?
CodePudding user response:
I was able to cancel the merge by cancelling the commit, and to keep my local changes by doing:
git reset --soft HEAD~1
CodePudding user response:
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, e.g. 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, e.g. 134124124124>
.
Then you could cherry pick any commits you made on your old branch after the merge commit, e.g. git cherry-pick 123123123
.