Cant commit after starting a merge in Sourcetree

后端 未结 5 1273
后悔当初
后悔当初 2020-12-28 13:43

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

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

<
相关标签:
5条回答
  • 2020-12-28 13:53

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

    0 讨论(0)
  • 2020-12-28 14:02

    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.

    0 讨论(0)
  • 2020-12-28 14:04

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

    0 讨论(0)
  • 2020-12-28 14:07

    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

    0 讨论(0)
  • 2020-12-28 14:09

    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.

    0 讨论(0)
提交回复
热议问题