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

340,745

Solution 1

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

Solution 2

git commit -am 'Conflicts resolved'

This worked for me. You can try this also.

Solution 3

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"

Solution 4

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"

Solution 5

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.

Share:
340,745
pMan
Author by

pMan

duh! https://github.com/pMan

Updated on July 10, 2022

Comments

  • pMan
    pMan almost 2 years

    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.

  • pMan
    pMan about 13 years
    I never used rebase or cherry-pick before, I just ran through the manual now, so what would you suggest, "git rebase master" after merging conflicts will work?
  • Talljoe
    Talljoe about 13 years
    It's a parallel workflow. See stackoverflow.com/questions/804115/git-rebase-vs-git-merge Basically, if you want the "merge" to be separate commits you instead rebase the source branch onto the end of the target branch.
  • Peter DeWeese
    Peter DeWeese almost 13 years
    Just git add each individual file then commit without -a.
  • ftrotter
    ftrotter almost 12 years
    you did not actually answer the question but rather simply gave more to search for. Now we need to know "what is cherry picking" and "what is rebase".
  • pMan
    pMan over 10 years
    I wonder why this answer was down-voted. I always had the child's curiosity when somebody tells me things I never knew before. As I commented above, now I know about cherry pick and rebase. Wasn't that progressive/helpful?
  • jcalfee314
    jcalfee314 over 10 years
    What does Stage additional files mean?
  • MikaelHalen
    MikaelHalen over 10 years
    @jcalfee314 staging in git is to prepare the file for the commit. In this particular case it stages the file via command line before committing. The -i flag is used mostly for when you are concluding a merge. You could read more about the commit flags here.
  • Lee Goddard
    Lee Goddard almost 10 years
    Not in 1.9.0 — the commit -i worked, but not git add; git commit
  • Coxy
    Coxy almost 9 years
    thanks, but unfortunately this didn't work for me. Annoyingly, I had to commit a view-private as well as the merge before it would let me commit the merge.
  • JonSlowCN
    JonSlowCN over 8 years
    @jcalfee314 I checked the documentation and it says "Before making a commit out of staged contents so far, stage the contents of paths given on the command line as well. This is usually not what you want unless you are concluding a conflicted merge". My guess is that under this condition, there is some kind of inconsistency in the staging area that can't be solved by git add, which makes git commit fail. Adding -i would tell git to add and commit at the same time. I'm still not sure why but it seems to make sense.
  • Fookatchu
    Fookatchu about 8 years
    Please do not post duplicate answers. While the underlying problem may be the same, your answer is for a much more specific problem and only clouds the answers to this general question. I think in this case a comment to the question in which you link to your original answer is more appropriate.
  • Florian G
    Florian G almost 8 years
    ah ah! I forgot again!
  • JeanValjean
    JeanValjean over 7 years
    Amazing, I did not know this!
  • Kyle Baker
    Kyle Baker over 7 years
    Could you explain this more? This is probably what I need, but I don't follow how it would work... All the answers here are just 'add the files, then commit!', but that's so trivially obvious; the reason I'm here is I don't want to add those files before I commit. -_-;
  • Kyle Baker
    Kyle Baker over 7 years
    That helps. Thanks. :)
  • Chase Sandmann
    Chase Sandmann about 7 years
    This adds all modified files to the commit, even ones that are unstaged which may not be desirable. Users may want to leave off the 'a' flag
  • Michael
    Michael almost 7 years
    This is exactly what the user is asking not to do, which is to avoid committing all files.
  • Narendra Pandey
    Narendra Pandey almost 7 years
    Thanks, it helped
  • Skystrider
    Skystrider almost 6 years
    For noobs like myself, you will also get this same error if you try a message that includes spaces without quotes. Eg. [git commit -m one two three] Correct: [git commit -m "one two three"]
  • contributorpw
    contributorpw almost 6 years
    It's so obvious and so confusing at the same time!
  • Noumenon
    Noumenon over 5 years
    -i stands for "include this file", not "interactive" as I had assumed.
  • MikaelHalen
    MikaelHalen over 5 years
    @noumenon it is a bit confusing since -i can correspond to the --interactive flag in other git commands. You are partly correct in your point that it means "include this file"; it stands for --include which potentially could include multiple files.
  • Abhrajyoti Kirtania
    Abhrajyoti Kirtania about 5 years
    Worked for me too..Thanks!
  • Shashank Bodkhe
    Shashank Bodkhe almost 5 years
    Worked for me as-it-is
  • tontonCD
    tontonCD over 4 years
    Great! That'd work for me. By the way if on MacOS, from the terminal you could have call ` open .git`, witch will display the '.git' content in the Finder
  • vandu
    vandu over 4 years
    This works for me too. This should be accepted as answer.
  • tehbeardedone
    tehbeardedone over 4 years
    @Skychan's comment was the ticket for me.
  • Aslan
    Aslan about 3 years
    This was my case too. Unfortunately I had to read all above before I find the solution... I was using it like this git commit "message" . you need -m in front of "message": git commit -m "message"