Git error on commit after merge - fatal: cannot do

2019-01-16 00:01发布

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

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

fatal: cannot do a partial commit during a merge.

I had the same issue before and using -a in 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.

标签: git commit
14条回答
一夜七次
2楼-- · 2019-01-16 00:30
git commit -am 'Conflicts resolved'

This worked for me. You can try this also.

查看更多
Root(大扎)
3楼-- · 2019-01-16 00:32

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

This should work.

git commit -m "Fixing merge" 
查看更多
干净又极端
4楼-- · 2019-01-16 00:33

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.

查看更多
迷人小祖宗
5楼-- · 2019-01-16 00:34

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 add that file and then git commit -m "Merge conflict resolution". The -i flag for git commit does the add for you.

查看更多
可以哭但决不认输i
6楼-- · 2019-01-16 00:34

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

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

Cheers

查看更多
你好瞎i
7楼-- · 2019-01-16 00:36

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.

查看更多
登录 后发表回答