3

Until yesterday my project has only a branch with a .gitignore file similar to:

*.log
upload/*
!upload/global/empty.txt

It worked fine until I added a new branch and changed this .gitignore to not ignore upload files. The new .gitignore file remained with only one line:

*.log

I returned to master branch without problems, but now each time I want to go to the new branch I receive a message like this:

error: Untracked working tree file 'upload/file.txt' would be overwritten by merge.

I need to checkout this branch to work with it or, at least, rescue the commits I made.

Note: I've found this similar question, but doesn't answer my question.

Community
  • 1
  • 1
Ivan
  • 14,692
  • 17
  • 59
  • 96
  • So you removed the line `*.log` from your `.gitignore` file, in your new branch? And you still have `upload/*` in the `.gitignore' file in both branches? – Andy Dec 10 '11 at 16:59
  • No, I removed the "upload/*" and "!upload/global/empty.txt" lines – Ivan Dec 10 '11 at 17:01

1 Answers1

9

Your issue is that in the new branch you are not tracking upload/file.txt but you are tracking it in your master branch. So when you switch to your new branch, your version, from master, will overwrite the untracked file.

Add the -f flag, to your git checkout, to force git to overwrite the untracked file.

Peter Gluck
  • 8,168
  • 1
  • 38
  • 37
Andy
  • 44,610
  • 13
  • 70
  • 69
  • It works, I'm able to change branches. But it gives a list of errors "unable to unlink" for each file in the *upload* folder. Git status says "nothing to commit" in both branches. Is possible to avoid this errors or should I live with it? :) – Ivan Dec 10 '11 at 17:19