Git“您还没有完成合并”并且没有什么可提交的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9143561/
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 12:54:03  来源:igfitidea点击:

Git "You have not concluded your merge" and nothing to commit?

git

提问by Tower

Whenever I try to push in Git I get this:

每当我尝试推送 Git 时,我都会得到以下信息:

You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

Running git statusI get:

运行git status我得到:

# On branch master
nothing to commit (working directory clean)

Or running git ls-files -uI get nothing.

或者运行git ls-files -u我什么也得不到。

Running git add .and trying again makes no difference.

运行git add .并再次尝试没有任何区别。

What's up?

这是怎么回事?

回答by Tower

Okay I finally found answer: git commit -m "Test"apparently fixed this. The result was an empty commit with no changes whatsoever. Even Github shows an empty commit, but it works.

好的,我终于找到了答案:git commit -m "Test"显然已经解决了这个问题。结果是一个空提交,没有任何更改。甚至 Github 也显示了一个空提交,但它有效。

回答by dahlbyk

Did you end up with an empty merge commit (two parents) or just an empty commit? In the latter case, you could have deleted .git/MERGE_HEAD.

你最终得到的是一个空的合并提交(两个父母)还是一个空的提交?在后一种情况下,您可以删除.git/MERGE_HEAD.

Update:Rather than delete MERGE_HEADby hand, you could also use git merge --abort(as of git 1.7.4) or git reset --merge(as of git 1.6.2).

更新:MERGE_HEAD您也可以使用git merge --abort从 git 1.7.4 开始)或git reset --merge从 git 1.6.2 开始),而不是手动删除。

It's also worth mentioning that at least as of git 1.8.3 (maybe earlier?) you should see a statusmessage like this if an actual merge is in progress and needs to be committed (if you specified --no-commit, for example):

还值得一提的是,至少从 git 1.8.3(也许更早?)开始,status如果实际合并正在进行并且需要提交(--no-commit例如,如果您指定了),您应该看到这样的消息:

# On branch master
# All conflicts fixed but you are still merging.
#   (use "git commit" to conclude merge)
#
nothing to commit, working directory clean

If you don't see this and still get the MERGE_HEADwarning, something is messed up and you should probably just --abortto get back to a clean state.

如果您没有看到这一点并且仍然收到MERGE_HEAD警告,则说明有问题,您可能应该只是--abort回到干净的状态。

Additional Detail from Comments

评论中的其他详细信息

During a merge, git creates a MERGE_HEAD file in the root of the .git folder (next to HEAD, ORIG_HEAD, probably FETCH_HEAD, etc) to track information about the merge in progress (specifically, the SHA(s) of the commit(s) being merged into the current HEAD). If you delete that, Git will no longer think a merge is in progress. Obviously, if a merge really is in progress then you wouldn't want to delete this file.

在合并期间,git 在 .git 文件夹的根目录中创建一个 MERGE_HEAD 文件(在 HEAD、ORIG_HEAD 旁边,可能是 FETCH_HEAD 等)以跟踪有关正在进行的合并的信息(特别是提交的 SHA(s) ) 合并到当前 HEAD 中)。如果删除它,Git 将不再认为合并正在进行中。显然,如果合并确实在进行中,那么您不会想要删除此文件。

回答by Andrei Konstantinov

Use git resetcommand, without parameters. Docs

使用git reset命令,不带参数。 文档