Git error on commit after merge - fatal: cannot do a partial commit during a merge
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
- Stage only the conflicted file (
git add your_file.txt
) 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.
Comments
-
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 about 13 yearsI 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 about 13 yearsIt'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 almost 13 yearsJust git add each individual file then commit without -a.
-
ftrotter almost 12 yearsyou 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 over 10 yearsI 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 over 10 yearsWhat does
Stage additional files
mean? -
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 almost 10 yearsNot in 1.9.0 — the
commit -i
worked, but notgit add; git commit
-
Coxy almost 9 yearsthanks, 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 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 makesgit 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 about 8 yearsPlease 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 almost 8 yearsah ah! I forgot again!
-
JeanValjean over 7 yearsAmazing, I did not know this!
-
Kyle Baker over 7 yearsCould 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 over 7 yearsThat helps. Thanks. :)
-
Chase Sandmann about 7 yearsThis 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 almost 7 yearsThis is exactly what the user is asking not to do, which is to avoid committing all files.
-
Narendra Pandey almost 7 yearsThanks, it helped
-
Skystrider almost 6 yearsFor 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 almost 6 yearsIt's so obvious and so confusing at the same time!
-
Noumenon over 5 years
-i
stands for "include this file", not "interactive" as I had assumed. -
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 about 5 yearsWorked for me too..Thanks!
-
Shashank Bodkhe almost 5 yearsWorked for me as-it-is
-
tontonCD over 4 yearsGreat! 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 over 4 yearsThis works for me too. This should be accepted as answer.
-
tehbeardedone over 4 years@Skychan's comment was the ticket for me.
-
Aslan about 3 yearsThis 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"