Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch branch when filename case changes?

Tags:

git

  1. I have a branch development with a file Config.json.
  2. I am creating a new branch new_development, where I rename Config.json to config.json and commit.
  3. I switch back to development to see how some things were made in that branch. No errors.
  4. I switch to new_development to continue work on new stuff. It shows an error:

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

   Config.json

Please move or remove them before you switch branches.

Aborting

The file is actually in git.

I have this git config:

[core]
    ignorecase = false

How do I make branches switching work when the same files have different case?

like image 566
Sergei Basharov Avatar asked Apr 30 '18 07:04

Sergei Basharov


1 Answers

How do I make branches switching work when the same files have different case?

Change core.ignoreCase back to true.

You are on a case insensitive filesystem; git uses the core.ignoreCase setting to indicate that. It is configured when you create a repository (either via git init or by git clone): git looks at your filesystem to determine whether it's case sensitive or not, and caches that information (in the core.ignoreCase setting) so that it doesn't have to do this lookup for every operation.

This is not a setting that is meant for you to change.

With core.ignoreCase = false, on a case insensitive filesystem:

% git ls-tree HEAD
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99    foo
% git ls-tree branch
100644 blob bcc9cdfd113753edf279e92afd622b0f3bb05fbc    FOO
% git checkout branch
error: The following untracked working tree files would be overwritten by checkout:
    FOO
Please move or remove them before you switch branches.
Aborting

This is because I've told git that my filesystem is case sensitive. It looks at the tree that I'm trying to check out, sees that there's a file called FOO that is not in my current HEAD tree, and then looks on disk to see if there's an untracked working file with the same name. It stats the file FOO (which is really the file foo, since we're on a case insensitive filesystem) and realizes that you have an untracked file in the working directory.

Except, of course, you don't. You have the file foo.

If I correct this, setting core.ignoreCase to reflect the reality of my filesystem, then I can switch branches properly:

% git config core.ignoreCase true
% git checkout branch
Switched to branch 'branch'
% git ls-tree HEAD
100644 blob bcc9cdfd113753edf279e92afd622b0f3bb05fbc    FOO
like image 161
Edward Thomson Avatar answered Oct 19 '22 00:10

Edward Thomson