347

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.

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
pMan
  • 8,808
  • 11
  • 32
  • 35
  • 8
    And you know, searching for [git perform "full commit"](https://www.google.com/search?q=git+perform+a+"full+commit") returns nearly nothing useful. Not one relevant document from Git's man pages. This is such a miserable tool. – jww Jun 15 '16 at 07:31
  • 8
    @Torek - talk about another mess created by Git... Why is it so god damn difficult to checkout a conflicted file from another branch so the conflict is averted, add it to this branch, and then commit it??? And WTF is a partial commit? I can't find any documentation on it... Users are forced to try the guesses below... – jww Jul 01 '16 at 18:03
  • How did you do it? I have a conflict and I can't do anything – Niklas Rosencrantz Nov 14 '17 at 15:14

21 Answers21

515

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
MikaelHalen
  • 5,772
  • 1
  • 18
  • 16
  • 25
    What does `Stage additional files` mean? – jcalfee314 Jan 06 '14 at 18:57
  • 10
    @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](https://www.kernel.org/pub/software/scm/git/docs/git-commit.html). – MikaelHalen Jan 07 '14 at 08:04
  • 4
    @jcalfee314 I checked [the documentation](http://git-scm.com/docs/git-commit) 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. – JonSlowCN Aug 21 '15 at 09:13
  • 10
    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"] – Skystrider Jun 20 '18 at 21:23
  • `-i` stands for "include this file", not "interactive" as I had assumed. – Noumenon Jan 03 '19 at 23:23
  • 1
    @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. – MikaelHalen Jan 14 '19 at 09:18
148
git commit -am 'Conflicts resolved'

This worked for me. You can try this also.

Pratip Ghosh
  • 1,810
  • 1
  • 12
  • 20
  • 20
    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 – Chase Sandmann Apr 03 '17 at 23:14
  • 12
    This is exactly what the user is asking not to do, which is to avoid committing all files. – Michael Jun 09 '17 at 21:09
46

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"
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
aWebDeveloper
  • 36,687
  • 39
  • 170
  • 242
28

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"
Post Self
  • 1,471
  • 2
  • 14
  • 34
wgeorge
  • 281
  • 3
  • 2
18

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.

Paul Price
  • 2,657
  • 30
  • 26
14

Looks like you missed -m for commit command

Sushil Adokar
  • 370
  • 5
  • 9
  • 1
    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" – Aslan Feb 23 '21 at 14:27
10

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" 
Asim Jalis
  • 884
  • 9
  • 8
9
  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 .
Ahmed Samir
  • 291
  • 3
  • 6
  • 1
    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 – tontonCD Nov 20 '19 at 10:37
  • This works for me too. This should be accepted as answer. – vandu Dec 17 '19 at 06:01
9

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

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Surajit Sarkar
  • 111
  • 1
  • 3
6

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

Moyshe Zuchmir
  • 1,522
  • 12
  • 18
5

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.

Zds
  • 4,311
  • 2
  • 24
  • 28
  • 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 Oct 12 '16 at 15:45
  • That helps. Thanks. :) – Kyle Baker Oct 26 '16 at 17:13
5

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
zx485
  • 28,498
  • 28
  • 50
  • 59
FelipeNutz
  • 51
  • 1
  • 1
5

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.

Ketan Patel
  • 157
  • 1
  • 2
  • 6
3

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.

Justin
  • 17,670
  • 38
  • 132
  • 201
  • 1
    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. – Coxy Jul 14 '15 at 05:30
3

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.

Tree Conflict Screenshot

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.

Look at all these Mods and Added files

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

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Plexander
  • 61
  • 2
  • 2
    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. – Fookatchu Feb 22 '16 at 09:39
3

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

luky
  • 2,263
  • 3
  • 22
  • 40
2

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.

Community
  • 1
  • 1
szeitlin
  • 3,197
  • 2
  • 23
  • 19
2

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.

cgr
  • 4,578
  • 2
  • 28
  • 52
2

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.

Talljoe
  • 14,593
  • 4
  • 43
  • 39
  • 1
    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? – pMan Apr 29 '11 at 05:01
  • 1
    It's a parallel workflow. See http://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. – Talljoe Apr 29 '11 at 05:17
  • 1
    Just git add each individual file then commit without -a. – Peter DeWeese Jul 20 '11 at 17:17
  • 4
    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". – ftrotter Aug 18 '12 at 20:13
  • 2
    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? – pMan Oct 08 '13 at 06:07
1

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?

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
0

Git does not allow a partial commit during a merge. -i/--include is not allowed either now(v2.40.0). When you want to merge only some of the files, a workaround is to use squash merge first, resolve the conflicts if any, and then commit the interested files only. The "cons" are that only changes are introduced while the commit history is not. After all, the commit history is the snapshots of all files.

git pull origin $branch --squash
# Or
git fetch origin $branch
git merge FETCH_HEAD --squash

# If there is any conflict in the interested files,
# resolve it and then add the files.
# If it's in the uninterested files, add the files without resolving it.

# Commit the interested files only.
git commit -m "message" file.php

# Discard the changes in the other files.
git reset --hard
# Or
git stash

Note that if there is any changed file you still want to preserve, git reset --hard is too brutal. You could use git reset $file; git checkout $file to discard the changes of the specific file only.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53