Cant commit after starting a merge in Sourcetree

。_饼干妹妹 提交于 2019-12-18 12:47:44

问题


When trying to commit after a merge I'm getting this error message:

"fatal: You are in the middle of a merge -- cannot amend."

How do i resolve this? as far as I know I have resolved all conflicts, i just need to complete the merge and commit the changes. but the product won't let me and doesn't give me any clues as to what I am meant to do next, and there is no option to "complete the merge"

Everytime I try to commit my changes I get the error message and I now have no idea what to do about it!


回答1:


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.

Please read:

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




回答2:


Do a git commit -a once you have resolved the conflicts. This is the last step when you are merging conflicts.




回答3:


After resolving the conflicts,you should try "git rebase --continue" for the rebase to complete.Post that, commit --amend is allowed.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/22135465/cant-commit-after-starting-a-merge-in-sourcetree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!