Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull fails with "Untracked working tree file 'blah' would be overwritten by merge", but tree is clean

Tags:

git

I've checked in some changes to my local repository that I want to push, but when I do a git pull, I get:

paul$ git pull 

error: Untracked working tree file 'documentation/Android/SwiftKey/buttons.xcf' would be overwritten by merge. Aborting

My working tree contains no untracked files:

paul$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 26 different commit(s) each, respectively.
#
nothing to commit (working directory clean)

The commits that I've made do not touch the file that it's complaining about.

I've read answers suggesting that I do a git reset HEAD --hard, but I'm not sure what effect that will have on the commits that I've made?

like image 604
Paul Butcher Avatar asked Jul 02 '10 12:07

Paul Butcher


1 Answers

It's not the commits you've made that touch the file, but the commits that you're pulling. Inspect the remote branch you're tracking to see what's happened. For example, git log master..origin/master will show all the commits that have happened on origin/master since you last pulled. According to your output above, there are 26 of these. Using the --name-status option will show which commit added the file.

You will need to rename the offending file, do the pull, and then move it back (overwriting the copy from the repo). git diff filename will then tell you how your copy differs from the one that someone else has committed to master. You can then commit the differences, or throw them away with git checkout filename.

You will need to use git pull --rebase to rebase your recent commits on top of the ones in origin. Once git status says master is ahead rather than diverged from origin/master, you can push.

like image 171
Neil Mayhew Avatar answered Nov 03 '22 21:11

Neil Mayhew