git 在 Sourcetree 中开始合并后无法提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22135465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:49:35  来源:igfitidea点击:

Cant commit after starting a merge in Sourcetree

gitatlassian-sourcetree

提问by johnvdenley

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!

每次我尝试提交更改时,都会收到错误消息,现在我不知道该怎么做!

回答by Brian Gordon

You can manually delete .git/MERGE_HEADand 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.

您可以手动删除.git/MERGE_HEAD,Git 将无法判断您只是在进行合并。它将让您像往常一样使用索引中的更改来修改先前的提交。

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 -aas per this answer

虽然这会奏效,但这是一种黑客行为,不推荐。这里需要做的就是让 git 知道合并已git commit -a按照此答案完成

回答by user376507

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

git commit -a一旦你解决了冲突,就做一次。这是合并冲突时的最后一步。

回答by dinesh kaki

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

解决冲突后,您应该尝试“git rebase --continue”以完成rebase。发布后,commit --amend 是允许的。

回答by dinesh kaki

This happens because you have files conflict. When you do a git merge branchand don't have any conflict, git makes a commit automatically, then you must do a git commit --amendto 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 commitwithout --amend.

发生这种情况是因为您有文件冲突。当你做 agit merge branch并且没有任何冲突时,git 会自动进行一次提交,那么你必须执行 agit commit --amend来更改提交消息。但是,当有冲突时,没有提交,因为 git 期望你解决它们,所以当你完成解决冲突时,只需执行一个git commitwithout --amend

回答by quintin

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.

否则,我们可能会陷入合并和提交循环。