我做了一件蠢事,结果引起了冲突。我解决了冲突,现在一切都好了(我也使用了mergetool)。

当我用git commit file.php -m "message"提交解析文件时,我得到了错误:

fatal: cannot do a partial commit during a merge.

我以前遇到过同样的问题,在commit中使用-a工作得很好。我认为这不是完美的方式,因为我不想提交所有的更改。我想用单独的注释单独提交文件。我该怎么做呢?为什么git不允许用户在合并后单独提交文件?对于这个问题,我找不到满意的答案。


当前回答

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

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

只运行冲突文件(git add your_file.txt) Git commit -m "your_merge_message"

其他回答

有时在合并过程中,如果出现冲突,并且存在需要手动解决的增量。在这种情况下,修复手动解决文件提到。

如果你提出,

git status Lib/MyFile.php

您将看到如下输出

On branch warehouse
Your branch and 'origin/warehouse' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

    modified:   Lib/MyFile.php

因为您已经执行了提交,所以您只需要发布

git commit

你的承诺将会毫无问题地完成。

在合并过程中,Git出于各种原因想要跟踪父分支。你要做的不是git所看到的merge。您可能想要手动进行基数调整或选择。

如果你使用的是源树或其他图形用户界面,确保所有文件都被检查(合并后)。

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

git commit "commit message"

应该是

git commit -m "commit message"
git commit -am 'Conflicts resolved'

这对我很管用。你也可以试试这个。