合并后提交时出现 Git 错误 - 致命:合并期间无法进行部分提交

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

Git error on commit after merge - fatal: cannot do a partial commit during a merge

gitcommit

提问by pMan

I ran a git pullthat ended in a conflict. I resolved the conflict and everything is fine now (I used mergetool also).

我跑了git pull一个以冲突结束的。我解决了冲突,现在一切都很好(我也使用了 mergetool)。

When I commit the resolved file with git commit file.php -m "message"I get the error:

当我提交已解决的文件时,git commit file.php -m "message"出现错误:

fatal: cannot do a partial commit during a merge.

I had the same issue before and using -ain commit worked perfectly. I think it's not the perfect way because I don't want to commit all changes. I want to commit files separately with separate comments. How can I do that? Why doesn't git allow users to commit files separately after a merge? I could not find a satisfactory answer to this problem.

我之前遇到过同样的问题,并且-a在提交中使用效果很好。我认为这不是完美的方式,因为我不想提交所有更改。我想用单独的注释单独提交文件。我怎样才能做到这一点?为什么git不允许用户在合并后单独提交文件?我找不到这个问题的满意答案。

回答by MikaelHalen

I found that adding "-i" to the commit command fixes this problem for me. The -i basically tells it to stage additional files before committing. That is:

我发现在提交命令中添加“-i”可以为我解决这个问题。-i 基本上告诉它在提交之前暂存其他文件。那是:

git commit -i myfile.php

回答by Pratip Ghosh

git commit -am 'Conflicts resolved'

This worked for me. You can try this also.

这对我有用。你也可以试试这个。

回答by aWebDeveloper

You can use git commit -ifor most cases but in case it doesn't work

您可以git commit -i在大多数情况下使用,但万一它不起作用

You need to do git commit -m "your_merge_message". During a merge conflict you cannot merge one single file so you need to

你需要做git commit -m "your_merge_message"。在合并冲突期间,您无法合并单个文件,因此您需要

  1. Stage only the conflicted file ( git add your_file.txt)
  2. git commit -m "your_merge_message"
  1. 仅暂存冲突的文件 ( git add your_file.txt)
  2. git commit -m "your_merge_message"

回答by Paul Price

You probably got a conflict in something that you haven't staged for commit. git won't let you commit things independently (because it's all part of the merge, I guess), so you need to git addthat file and then git commit -m "Merge conflict resolution". The -iflag for git commitdoes the add for you.

你可能在一些你没有准备提交的事情上遇到了冲突。git 不会让你独立提交事情(因为它是合并的一部分,我猜),所以你需要git add那个文件,然后git commit -m "Merge conflict resolution". 在-i为标志git commit是否添加你。

回答by wgeorge

I got this when I forgot the -min my git commit when resolving a git merge conflict.

当我-m在解决 git 合并冲突时忘记了git commit 时,我得到了这个。

git commit "commit message"

should be

应该

git commit -m "commit message"

回答by Asim Jalis

As the error message says you cannot do a partial commit after a merge. Instead of committing just file.phpyou should commit all the changes.

正如错误消息所说,您不能在合并后进行部分提交。file.php您应该提交所有更改,而不是仅提交。

This should work.

这应该有效。

git commit -m "Fixing merge" 

回答by Moyshe Zuchmir

Your merge stopped in the middle of the action. You should add your files, and then 'git commit':

您的合并在操作中间停止。你应该添加你的文件,然后“git commit”:

git add file_1.php file_2.php file_3.php git commit

git add file_1.php file_2.php file_3.php git commit

Cheers

干杯

回答by Ahmed Samir

  1. go to your project directory
    1. display hidden files (.git folder will appear)
    2. open .git folder
    3. remove MERGE_HEAD
    4. commit again
    5. if git told you that git is locked go back to .git folder and remove index.lock
    6. commit again everything will work fine this time .
  1. 转到您的项目目录
    1. 显示隐藏文件(会出现.git文件夹)
    2. 打开.git文件夹
    3. 删除 MERGE_HEAD
    4. 再次提交
    5. 如果 git 告诉您 git 已锁定,请返回 .git 文件夹并删除 index.lock
    6. 再次提交,这次一切都会正常进行。

回答by Zds

If you just want to ditch the whole cherry-picking and commit files in whatever sets you want,

如果您只想放弃整个挑选并以您想要的任何集合提交文件,

git reset --soft <ID-OF-THE-LAST-COMMIT>

gets you there.

带你到那里。

What soft reset does is it moves the pointer pointing to current HEAD to the commit(ish) you gave but does not alter the files. Hard reset would move the pointer and also revert all files to the state in that commit(ish). This means with soft reset you can clear the merge status but keep the changes to actual files and then commit or reset them each individually per your liking.

软重置的作用是将指向当前 HEAD 的指针移动到您提供的提交(ish),但不会更改文件。硬重置将移动指针并将所有文件恢复到该提交(ish)中的状态。这意味着通过软重置,您可以清除合并状态,但保留对实际文件的更改,然后根据您的喜好单独提交或重置它们。

回答by Justin

For myself this happened in SourceTree when I tried to commit a merge before resolving all of the files. I then marked the last file resolved and yet it still gave me this error when trying to commit. I closed SourceTree and reopened it, and then it committed fine.

就我自己而言,当我在解析所有文件之前尝试提交合并时,这发生在 SourceTree 中。然后我将最后一个文件标记为已解决,但在尝试提交时它仍然给我这个错误。我关闭了 SourceTree 并重新打开它,然后它提交得很好。