Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I ran a git pull that ended in conflict. I resolved the conflict and everything is fine now (I used merge tool 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.

3 Answers

+1 vote
by (62.9k points)

By adding "-i" to the commit command would fix this problem for you. Basically, in simple terms the -i tells git to stage additional files before committing them without explicitly using the git add command, like this:

git commit -i myfile.php

0 votes
by (37.3k points)

In order to improve commit management and address your situation:

  1. Complete the Merge: First, commit all resolved modifications to finish the merge. With git commit, you may accomplish this without providing any file names:

            git commit -m 

  1. Make Separate Commits: If more modifications are required after the merging commit, you can make separate commits for them. Git add can be used to stage individual files, which can then be committed independently using Git.  
    git add file1.php git commit -m "Commit message for file1.php" git add file2.php git commit -m "Commit message for file2.php"

  1. Use Staging Area: You can use the staging area to selectively stage files if you wish to have your changes ready for separate commits but still need to deal with merge conflicts:
    git add path/to/file1.php git add path/to/file2.php

  2. After the required files have been staged, you can finish the merging commit:

            git commit -m 

Once the merging is finished, you can resume adding and committing changes as normal. These methods give you the ability to manage commitments for individual files separately, while still ensuring that your merging is performed successfully.

0 votes
by (1.7k points)

Finish the merge by executing

git commit -m “Merge completed”

Make the rest of the changes in chain without conflicts and make only then make separate commits for other changes.

Why This Happens?

When context is necessary to understand all of the contained changes, Git forbids making separate commits in the middle of a merge.

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...