Alex Rivera | Logout

Unresolvable Git error: The following untracked working tree files would be overwritten by checkout

Asked 2012-01-12T17:14:00.287
10

I am using Git alone for my local software project in Visual Studio 2010. Recently I created a new branch to do a larger refactoring of one of the dialogue windows. I did the following modifications:

  • Rename Form1 to Form1a (including all depending files)
  • Add new Form1

I checked this change into the branch, say form-refactoring. Interestingly, Git didn't notice that I renamed the file Form1.cs into Form1a.cs and created a brand new, totally different Form1.cs, but instead it noticed a new Form1a.cs file and found a whole lot of differences between the previous and new Form1.cs files. This will of course lead to totally garbaged diffs, but I don't care in this case as long as all files are handled correctly in the end.

Then I switched back to master to do some other small changes. Nothing conflicting. Until now, everything worked fine.

Today, I wanted to switch back to my branch form-refactoring to continue that work. But all I get is the following message:

git.exe checkout    form-refactoring

Aborting
error: The following untracked working tree files would be overwritten by checkout:
Form1.Designer.cs
Please move or remove them before you can switch branches.

What is that supposed to be? The mentioned file is not untracked. Neither in the master branch, nor in the form-refactoring branch. It is part of both branches, but one is not a descendent of the other. What would happen if I delete it, is it gone for good then? I don't trust Git to bring back the correct file if I delete something now. I did not play with any file at all outside of my mentioned Git operations, so why should I play around with any file to continue using Git operations now? Git broke it, Git's supposed to handle it now!

Right now, I cannot continue with my work because I cannot switch branches. Is there an easy solution to this?

Git version is 1.7.6, TortoiseGit is 1.7.3.

Edit
Report

1 Answer

1

Git doesn't allow to switch branches if there is a possibility of data lose.

Generally it is a good idea to commit all your changes before switching to another branch. If you are absolutely sure that you didn't make this change than you can reset your working tree using

git reset --hard HEAD

command. But I strongly don't recommend to do this. Use

git stash

command to stash your changes to internal storage. In this case you can always recover your data.

answered 2012-01-12T17:19:24.207

Your Answer