When trying to commit after a merge I\'m getting this error message:
<\"fatal: You are in the middle of a merge -- cannot amend.\"
After resolving the conflicts,you should try "git rebase --continue" for the rebase to complete.Post that, commit --amend is allowed.
This happens because you have files conflict. When you do a git merge branch
and don't have any conflict, git makes a commit automatically, then you must do a git commit --amend
to change the commit message. But, when there is conflicts, there is no commit, because git expect you to resolve them, so when you finish to solve the conflicts, just do a git commit
without --amend
.
Do a git commit -a
once you have resolved the conflicts. This is the last step when you are merging conflicts.
You can manually delete .git/MERGE_HEAD
and Git won't be able to tell that you were just doing a merge. It will let you amend the previous commit with the changes in your index just like normal.
Though this would work, it is a hack and not recommended. All is needed here is to let git know the merge is completed git commit -a
as per this answer
If you are trying to amend on a previous commit and you know there will be merge conflicts then force push the changes (if you are sure that you want your current changes to override remote changes).
First commit:
1. git add test.txt
2. git commit -m "some changes"
3. git push
Second commit after some changes in same file which will result in merge conflict and we know we want only the latest changes that we did in this file:
1. git add test.txt
2. git commit --amend
3. git push -f
Otherwise, we might get stuck in merge and commit loop.