0

There are changes in git I want to get rid off. Let's say the name of the file is ABC.sql If I do git restore ABC.sql, it brings up a file "abc.sql", then if I try doing git restore abc.sql, the "ABC.sql" file is back.

Apart from git restore, I have also tried:

  1. git checkout
  2. git reset

But nothing seems to help me get rid of this file. Any help would be much appreciated!

2 Answers2

1

I'm going to make 2 assumptions:

  1. You are working in Windows or OSX. Natively Windows is not case sensitive, and OSX is configured to not be case sensitive, but Git is.
  2. You have two files checked in with a similar filename differing by casing only.

You can check #2 by using Git Bash, and running this command from the root of your repo:

git ls-tree -r HEAD | grep -i abc.sql

If you see both files in the list: "abc.sql" and "ABC.sql", then you know that somehow both files got into the repo with a similar name. There are multiple ways this could happen, such as if there are some users of this repo that aren't using Windows, or the file was created on different branches with different casings and both were merged in.

The best course of action is to inspect both versions of the file, then either delete one or rename it (and commit the change) so that Windows users don't have this issue anymore. Depending on your remote Git service, there are typically settings you can enable to prevent anyone from pushing commits containing branches and files that differ by casing only. There are configs for this you can set in your local repo too, but it's better to stop the problem at the remote server level, if possible.

TTT
  • 22,611
  • 8
  • 63
  • 69
0

I am using OSX.

For me what worked was removing the file from cache: $git rm --cached abc.sql