1

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?

tristantzara
  • 5,597
  • 6
  • 26
  • 40

3 Answers3

4

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

$ git add .
$ git stash
$ git pull origin <branch-name> 
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • 1
    I definitely have all the changes committed – tristantzara Nov 24 '16 at 13:21
  • @TristanTzara Not just changes you've done while adding/modifying, but also changes while deleting. In this case, overwrite means that the file you've deleted will come back in the other branch, so you should stash/commit to preserve your changes to the working directory. – cst1992 Nov 24 '16 at 13:24
  • 2
    @TristanTzara: please add `git status` output to your original post, to show that there are no deletions yet to be committed. Otherwise I believe this is the correct answer: that you committed other changes, but not the deletion itself. – torek Nov 24 '16 at 13:34
  • @TristanTzara you are right I have now the same case (after 6 years) when all changes are commited/stashed and the same problem – griffon vulture Apr 26 '22 at 19:34
0

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.

cst1992
  • 3,823
  • 1
  • 29
  • 40
0

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:

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360