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

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

fatal: cannot do a partial commit during a merge.

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


当前回答

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

git commit -i myfile.php

其他回答

我用一种完全不同的方法解决了这个问题,只使用了Xcode的源代码控制。

背景:另一个团队将更改推送到远程Git存储库(通过Beanstalk)。在我这边,.xcodeproj文件放在不同的目录下,没有进行更改。后来,当我试图提交时,我在Xcode中收到了一个树冲突错误。

由于使用Xcode几乎不可能纠正错误,所以我用从Git服务器下载的版本替换了.xcodeproj文件。结果……Xcode项目似乎清理了,但是所有来自损坏的Pull的更新都显示为我所做的更改,并被提交。

然而,当尝试提交时,我收到了同样的“致命:不能在合并期间进行部分提交”错误,这里讨论。

Here's how I solved the problem... (Now, understand that I'm a rookie programmer, so I could lack some understanding... but my ignorance led me to find another way to do this.) First, I Cloned my master Branch into a secondary Branch and switched to that branch. Then I created a Working Copy and placed the directory to that working copy outside of the original project directory. (I don't know if this was necessary, but its what I did as I read other troubleshooting techniques.) Then I switched branches to the master, where I realized all my Staged files (changes to Commit) were gone. To make sure all the files were updated to the latest changes made by the other party, I created a new branch called ThirdBranch, which duplicated all files, Pushed it to the Git Server and let Beanstalk compare my server version of the master branch to the ThirdBrach branch I just Pushed (line by line), and all the changes by the other party were present on my Xcode. This meant that my master repository and the Git master repository were the same, which verifies that I solved the problem using Xcode, only.

不要问我是怎么做到的,除了我刚才描述的……当然也能填补我遗漏的空白。我是新手,也不是什么都懂。也许一个有经验的程序员可以将不相关的信息从相关信息中分离出来,并更清楚地重新创建这种技术,这也是我发布这篇文章的部分原因。

这是对重复问题的重复回答:失败的Xcode Git合并卡住了

你的合并在动作中间停止了。 你应该添加你的文件,然后'git commit':

git 添加file_1.php file_2.php file_3.php git 提交

干杯

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

git commit "commit message"

应该是

git commit -m "commit message"

看起来您错过了提交命令的-m

如果你只是想放弃所有的选择并提交你想要的文件集,

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

让你到达那里。

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