14

I'm working with git on windows, and I have a file in my repo, lets say "foo.txt". Today I wanted to rename this file to "Foo.txt" (uppercase). As suggested in this SO question, I used git mv -f foo.txt Foo.txt, which produced the desired result. I proceeded to commit the change to my repo.
EDIT: I would like this to be a permanent change, and still be able to checkout commit that predate this change.

However, after that I encountered an error upon trying to switch branch:

# I'm on branch1  
git checkout branch2  
Aborting  
error: The following untracked working tree files would be overwritten by checkout:  
Foo.txt  
Please move or remove them before you can switch branches.  

After some poking around I found that my .git/config file had the following setting:

[core]  
    ignorecase=false  

Changing this to true seems to fix the issue and allows me to change between branches as normal.

So regarding this, I would like to know:

  1. Is there any adverse effect of this setting? Should it always be true on windows? What if I'm working with other dev's and they don't have the same value set for this?
  2. Is there another way to rename the file without having to change this setting?
  3. Why does this happen in the first place? When I committed the change, git correctly identified that the file was in fact renamed (didn't delete one file and then add another). So what exactly happened when I tried to switch branches?

Thanks!

Community
  • 1
  • 1
avivr
  • 1,393
  • 15
  • 28

2 Answers2

4

As mentioned in "Unresolvable Git error: The following untracked working tree files would be overwritten by checkout", setting core.ignorecase to true is a valid way to allow the checkout to proceed.

But I would prefer, as in "GIT: The following untracked working tree files would be overwritten by checkout", to:

  • git add what I just modified (in your case, git mv might have already added the renamed file to the index)
  • git stash, saving the index
  • git checkout -b anotherBranch: this should work since the index is clean
  • git stash pop, if you want to restore the case change on that new index.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok, but i want to commit the rename. The problem is that if I do, i can't switch branches after that. – avivr Mar 19 '13 at 12:03
  • @avivr you can't switch after commit, even with `core.ignore` set to `false`? – VonC Mar 19 '13 at 12:05
  • No, like I said, I can only switch branch if it's set to true. Moreover, after I stashed the rename like you suggested, I got the same error when trying to pop the stash. So the stash was "unpopable" and I had to drop it. – avivr Mar 19 '13 at 12:13
  • @avivr sorry, I meant set to true, indeed. – VonC Mar 19 '13 at 12:16
3

A simple (but inelegant) way to overcome this problem without having to change the config setting is to delete the file and to check it out again. In my case this allowed my changes branches as normal again.

Edit: As Avivr has pointed out, my proposed workaround doesn't solve the problem permanently. I will still not delete this answer because it may help as a temporary hot-fix in some cases.

bigge
  • 1,488
  • 15
  • 27
  • 1
    This would mean i'd have delete the file every time I want to change branch, from now until forever. Right? That seems kind of inconvenient... – avivr Mar 19 '13 at 11:55
  • Did you actually try it? In my case it worked, but I will not claim that I could fully reproduce your situation – bigge Mar 19 '13 at 13:43
  • Yes, I did, at least assuming I understood you correctly. I renamed the file with git, then committed the change. Then I deleted the file (just with `rm`) and used `git checkout .` to restore it. After that, same error when changing branch. – avivr Mar 19 '13 at 16:39