2

If I checkout a git branch, sometimes a file path/to/File is deleted. I can see this as an unstaged change after the operation. It is always the same text file, which has not been edited for a long time. So it should be the same file at each branch. (But one branch calls it path/to/file.)

Usually I use Atlassian Sourcetree for switching branches, but the problem has also appeared on our gitlab ci/cd runner, which may use simple git command line commands.

The problem emerge at various clones of the repository and with various branches.

Is the repository somehow corrupted? Any idea how to resolve the problem?

torek
  • 448,244
  • 59
  • 642
  • 775
  • If someone on the other branch had deleted this file in the past, then it doesn't exist on that other branch, and Git may remove it when changing branches. – Tim Biegeleisen May 19 '22 at 10:52
  • @TimBiegeleisen Each branch actually should contain the file. It has not been changed in any branch, nor it has been deleted. – Christian Sattlecker May 19 '22 at 10:55
  • 2
    To be clear, is the _file_ disappearing, or are the _changes_ to that file disappearing? – Tim Biegeleisen May 19 '22 at 10:56
  • @TimBiegeleisen The file is disappearing. After switching the branch, I can see an unstaged change "missing file". – Christian Sattlecker May 19 '22 at 10:58
  • 4
    What OS are you using ? this may be an issue with file names on a case insensitive file system (e.g: MacOS or Windows). more specifically : if from a terminal you run `ls file/that/appears/as/deleted`, does it show up ? – LeGEC May 19 '22 at 11:12
  • 1
    @LeGEC I am using Windows and the case insensitivity seems to be the problem. Thank you. Now, I have seen, that a colleague added the file to one branch with all lower letters. However, I cannot find, where the file has been deleted before. Strange. However, I am sure, I will solve the problem now. Thank you! – Christian Sattlecker May 19 '22 at 11:31
  • Related: [Git restore keeps switching between 2 files with same name but opposite case](https://stackoverflow.com/q/67094987/184546) – TTT May 19 '22 at 14:35
  • @ChristianSattlecker note the file wasn't deleted. When two files are checked into the repo and differ only by case, Windows is unable to have both simultaneously on the file system, so one of them is always going to appear as deleted to Git. – TTT May 19 '22 at 14:36

1 Answers1

2

This is a case sensitivity issue : git expects a file with a certain letterCase, but your system is fine with having a different Lettercase.

There may be two variants of bugs related to that :

  • git may have only one "version" of filename in its storage,
  • git may have both filename and FileName versioned in its storage.

Check the content of git's commit (git ls-tree HEAD:path/to/directory) to see what variant you have.

  • if it's the first one : "fixing" it just requires choosing the correct name in git's storage, and make sure you have the same correct name on disk,

  • if it's the second one : you will have to additionally compare the content of the two versions (one way is git diff HEAD:path/to/filename HEAD:path/to/FileName), and check which version should be kept.

a note : Windows treats mv filename FileName as a noop, the easiest way to change the case of a name on disk is to go through a temporary name mv filename tempfile && mv tempfile FileName

LeGEC
  • 46,477
  • 5
  • 57
  • 104