9

While trying to pull from a remote branch I get an error: Your local changes to the following files would be overwritten by merge: app/..../_shared.scss Git is asking to commit the file or to stash.

The problem is - I've already done git add . and git commit -am "trying to remove the error". The problem persist.

git status says: "nothing to commit (working directory clean)"

Does anyone know how to get rid of it?

ANSWER: Move the offending file to some other location. Then delete the offending file from your tree. Pull again. then diff the changes from your offending file over the file you just pulled. hack, but it works.

Note: I found the answer here (Git asks me to commit or stash even those changes are commited), but since no one up voted it in the original thought I should repost. It's a hack, but it's the fastest route to resolution.

Community
  • 1
  • 1
Kirill
  • 3,667
  • 4
  • 30
  • 35
  • If you've found the solution yourself, you should post it as an answer and accept it – it's helpful to other people who have the same problem! – Will Vousden Jun 10 '12 at 20:56
  • Will keep that in mind. I didn't find the solution myself, I simply found the solution on another question. However, it seems the owner of the other question didn't want to accept this (perfectly valid) solution as the correct one. Thus, this seemed like a good way to share. Will do what you suggested next time tho. Thanks! – Kirill Jun 12 '12 at 06:51
  • As for me I simply renamed the file then pulled again and it worked. Git didn't even care about the currently missing file. – user276648 May 19 '17 at 07:34
  • I have found no solution to this problem. The repo is irreparably broken at this point and the only option is to nuke it and start with a fresh Clone. – gonewiththewhind Nov 17 '21 at 21:18

4 Answers4

6

If git status reported the working directory clean, I'd bet you have an ignored file in your working directory that somebody else added to the remote repo. You could confirm that with git diff --stat your-branch remote-name/remote-branch and git ls-files -i --exclude-standard.

The solution would be to remove the file from the ignore file (so git status shows it as an untracked file), stash it with the --include-untracked option, pull the changes from your remote, and apply the stash to merge your changes back in.

ellotheth
  • 4,333
  • 2
  • 17
  • 29
  • Can't really confirm or deny, now that I've used the workaround, but I will certainly try this next time. Judging on the work we were doing, you're most definitely correct. Thanks for the feedback! – Kirill Jun 12 '12 at 06:49
  • You saved my day! – Darshana Sep 08 '17 at 01:16
3

Or you could "force pull" as I tend to call it.

A fair warning: this snippet will destroy all local changes.
(including commited but not pushed changes)

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df
Pjetr
  • 1,372
  • 10
  • 20
0

I've tried to check for ignored files, as @ellotheth said, but it was not the problem. Only solution for me was to move the affected file.

However during commit there were many "unable to unlink files, permission denied" and I know that remotely some files were moved/added. Probably it has something to do with windows installation...Git Checkout warning: unable to unlink files, permission denied

Community
  • 1
  • 1
Glasnhost
  • 1,023
  • 14
  • 34
0

The above solutions did not work for me. I inserted a blank line to the problematic file and used the command git update-index --no-assume-unchanged /path/to/file. Then committed and pushed it normally.

Abdollah
  • 4,579
  • 3
  • 29
  • 49