Git: can't commit a file even though I've resolved the conflict
Solution 1
Okay, so this doesn't technically solve the original problem, but it does get around it. What I did was I backed up my changes to style.css
and then reset my local dev
branch to origin/dev
. This resolved whatever it thought the conflict was, since local and origin were now identical, but also put my local dev
branch one commit behind in the process.
So then I just diffed my backup style.css
(which had my most recent changes) against my now-current local version, merged my changes in, and committed.
Solution 2
I'll explain what basically happened here:
Your pull initiated a merge of the remote branch (because you did not do a rebase using the '-r' flag which would have done a rebase). The merge itself had a conflict and aborted (which also means your pull didn't finish). Now after you resolved the conflict you will have to add the conflicted file(s) and do a "git commit" to actually complete your pull (and the merge required for that). This will remove the file ".git/MERGE_HEAD" mentioned in your commit message which shows that you are currently in the middle of a merge.
After this you are in a clean state and everything should be fine.
Solution 3
I just had this myself and found this question while looking for a solution. The "Conflicts" message came up in my default text editor. Closing the text editor with gitshell still open allowed the commit to complete.
daGUY
Front-end web developer with 10 years of professional experience. Highly knowledgable of various web technologies, frameworks, and tools (HTML5, CSS/SCSS, JavaScript/jQuery, JSON, Zurb Foundation, Git, etc.). Multiple years of experience working in an Agile environment with Atlassian utilities (JIRA, Confluence, Stash, Bitbucket, etc.). Work experience ranges from tiny startups (employee #7!) to large international businesses (Mercedes-Benz, Nestlé), where I've written front-end code for a wide variety of projects including music streaming apps, corporate websites, and mobile-responsive landing pages and email campaigns.
Updated on June 04, 2022Comments
-
daGUY almost 2 years
I pulled from
origin
to update my local, and one file had conflicting changes. I resolved the conflict, but I can't commit (locally) because git still thinks the file is conflicting:$ git add style.css
This works - no errors or anything. Then:
$ git commit Merge branch 'dev' of [origin] into dev Conflicts: [path]/style.css # # It looks like you may be committing a MERGE. # If this is not correct, please remove the file # .git/MERGE_HEAD # and try again. #
Why doesn't this work?
-
bill-x almost 12 yearswhat does it show when you try
git status
? -
daGUY almost 12 yearsIt lists
style.css
as modified. However, I even tried discarding the changes entirely (they're minor), andgit commit
still saysstyle.css
is conflicting! -
vergenzt almost 12 yearsThat may just be the commit message. The default message lists files that had conflicts at the end just like that. Does
git log
show a merge? -
bill-x almost 12 yearshmm...have you tried to remove the file through explorer/file browser and then using
git rm <file>
(make sure you back it up in a non repo folder if you want it keep it). Commit again and push then re add the deleted file and commit/push? -
daGUY almost 12 years@vergenzt
git log
shows my last commit, but doesn't indicate it was a merge in any way. -
daGUY almost 12 years@BillX even if I delete the file and use
git rm
, it still tells me it's conflicting when I dogit commit
. -
vergenzt almost 12 yearsSo the
git commit
has no side-effect whatsoever? You could run it multiple times and nothing changes? -
bill-x almost 12 yearsDid you remove the file .git/MERGE_HEAD also?
-
-
daGUY almost 12 yearsThat sounds logical, but as you can see in my question, I did add the conflicting file but it still wouldn't let me commit. Unless you're saying I should have manually removed the
.git/MERGE_HEAD
file?