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.

2
  • 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? Commented Dec 10, 2011 at 16:59
  • No, I removed the "upload/*" and "!upload/global/empty.txt" lines Commented Dec 10, 2011 at 17:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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? :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.