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:
Thanks!
The Windows and macOS file systems are case-insensitive (but case-preserving) by default. Most Linux filesystems are case-sensitive. Git was built originally to be the Linux kernel's version control system, so unsurprisingly, it's case-sensitive.
Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.
you can do git checkout -m <branch-name> to merge conflicts and checkout to the branch and resolve conflicts yourself, or git checkout -f <branch-name> to ignore changes.
The git branch command lets you rename a branch. To rename a branch, run git branch -m <old> <new>. “old” is the name of the branch you want to rename and “new” is the new name for the branch.
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 indexgit checkout -b anotherBranch: this should work since the index is cleangit stash pop, if you want to restore the case change on that new index.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With