tristantzara
tristantzara

Reputation: 5917

Git says that a deleted file would be overwritten by merge

When I'm trying to git pull it won't let me, saying that local changes would be overwritten by merge. The thing is that the file it specifies, that it would be overwritten is deleted. I had it before but I deleted it and I can't see it neither from the editor tree view, nor from the file system. What kind of bug is that? How can I get rid of it and pull?

Upvotes: 1

Views: 677

Answers (3)

Sajib Khan
Sajib Khan

Reputation: 24194

Make sure you have committed all the changes. Otherwise, stash all the changes.

$ git add .
$ git stash
$ git pull origin <branch-name> 

Upvotes: 4

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522626

This isn't a bug as far as I know. I believe this situation arose because you deleted a certain file which is still present in the branch which is incoming during the merge.

Merging via git pull won't work as you showed us, but it appears that pulling via rebase should work. Try this:

git pull --rebase origin yourBranch

You will most likely get merge conflicts when you apply each of your commits on top of the new base. And the conflicts may include a situation where the file in question appears there but should really be deleted. In this case, if you want it gone the resolution may actually be to delete the file.

Here is a reference which mentions several possible solutions:

Git pull error: Your local changes to the following files would be overwritten by merge:

Upvotes: 0

cst1992
cst1992

Reputation: 3941

It's not a bug. It's a change, that will become ineffective if you pull(because your pulled branch will have different commits in it). Git wants you to preserve that change.

Stash that change using git stash or make a commit in another/new branch.

Upvotes: 0

Related Questions