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

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

fatal: cannot do a partial commit during a merge.

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


当前回答

我用一种完全不同的方法解决了这个问题,只使用了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不会让你独立提交东西(因为这都是合并的一部分,我猜),所以你需要git添加那个文件,然后git commit -m "合并冲突解决"。git commit的-i标志为你添加。

在阅读所有评论后。这就是我的决心: 我不得不再次“添加”它,而不是提交:

$ git commit -i -m support.html "doit once for all" [master 18ea92e] support.html

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

git commit -i myfile.php
git commit -am 'Conflicts resolved'

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

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

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

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