开发者

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

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. Ho开发者_如何转开发w 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.


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:

git commit -i myfile.php


git commit -am 'Conflicts resolved'

This worked for me. You can try this also.


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

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

  1. Stage only the conflicted file ( git add your_file.txt )
  2. git commit -m "your_merge_message"


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

git commit "commit message"

should be

git commit -m "commit message"


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.


Looks like you missed -m for commit command


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" 


  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 .


Simply git commit -m "comment" should work after resolving conflicts..


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


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.


After reading all comments. this was my resolution:
I had to "Add" it again than commit:

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


Sometimes during the merge, if conflicts arise and there are deltas that need manual resolution. In such case fix the manual resolution for the files mentioned.

Now if you issue,

git status Lib/MyFile.php

You will see output like

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

Since, you already staged the commit, you need just issue

git commit

And your commit will be done without any issue.


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.


I solved this with a completely different approach, using only Xcode's Source Control.

Background: Another team Pushed changes to the remote Git repository (via Beanstalk). On my end, the .xcodeproj files came in under different directory, and the changes didn't take. Later, when I tried to commit, I received a Tree Conflict error in Xcode.

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

Being nearly impossible to correct using Xcode, I replaced the .xcodeproj file with a downloaded version from the Git server. The result... the Xcode project appeared to clear up, however all the updates from the corrupt Pull were showing up as changes I made and were Staged for a Commit.

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

However when trying to Commit, I received the same "fatal: cannot do a partial commit during a merge" error, discussed here.

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.

Don't ask me how, beyond what I just described... and certainly fill in the gaps I left out. I'm new at this and I don't understand everything. Maybe an experienced programmer can separate the irrelevant info from the relevant and recreate this technique more clearly, which is in part why I'm posting this.

This is a duplicate answer to duplicate question as at: Failed Xcode Git Merge is stuck


If you are using Source tree or other GUI ensure all files are checked (after merge).


During a merge Git wants to keep track of the parent branches for all sorts of reasons. What you want to do is not a merge as git sees it. You will likely want to do a rebase or cherry-pick manually.


git commit -i -m 'merge message' didn't work for me. It said:

fatal: No paths with --include/--only does not make sense.

FWIW, I got here via this related question because I was getting this message:

fatal: You have not concluded your merge (MERGE_HEAD exists).

I also tried mergetool, which said No files need merging. Very confusing! So the MERGE_HEAD is not in a file that needs merging-??

Finally, I used this trick to add only the modified files (did not want to add all the files in my tree, since I have some I want to keep untracked):

git ls-files -m | xargs git add

Then I was finally (!) able to commit and push up. It sure would be nice if git gave you better hints about what to do in these situations.


If it is in Source Tree, we should explicitly mark a file as resolved after the conflicts are resolved. Select file that was just resolved to no conflicts. Then Actions -> Resolve Conflicts -> Mark Resolved. If you have multiple files, do the same for all. Commit now.


If there is a merge, you cannot do a partial commit, meaning you have to commit everything that has changed, added, or deleted.

In my case, files were pending deletion, but they were not included in the commit. Once I included them, my commit went fine in sourcetree (I did not have to use the command line).

Look immediately below the checked-in files, is there anything that has changed that is not included in the commit?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜