Source folder is not displaying all files in a directory
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Git is case-sensitive by default, meaning that it distinguishes between uppercase and lowercase letters when naming files. However, certain file partition types, such as HFS on MacOS and Windows, are case-insensitive. This means that files with the same name but different capitalization may exist within them. If you encounter an error when checking out a branch, the missing files may have the same name but with different cases. For example:
1
2
3
4
5
$ git switch branch
error: The following untracked working tree files would be overwritten by checkout:
test/one/File.txt
Please move or remove them before you switch branches.
Aborting
Environment
Any Git repository used on multiple file systems, including one that differs from the others.
Diagnosis
To diagnose the issue, you need to locate the Git file names in the repository using the file path and name for the missing file.
1. Get the last commit hash:
1
2
git log --pretty=oneline HEAD^..HEAD # Returns
9421372de22bd4c031815c067c74f2e41aaaec59 (HEAD -> one, origin/one) Test commit
2. Get the tree hash from the commit.
1
2
git cat-file -p 9421372de22bd4c031815c067c74f2e41aaaec59 | grep tree
tree 9b4f8ceb40b3031c542811ff2602bb22cbbae5a4
3. Iterate through the trees to look for the object. Each directory in git is a tree. So if the file is test/one/file.txt, as in this example, repeat this step for each directory to look for the file.
1
2
3
4
git cat-file -p 9b4f8ceb40b3031c542811ff2602bb22cbbae5a4 | grep test
040000 tree 0cf5c5159457b5b95126591f2a773b6de86c1993 test
git cat-file -p 0cf5c5159457b5b95126591f2a773b6de86c1993 | grep one
040000 tree 8d4f53e606d2061d5f4739c1d7835ed2b459ead8 one
4. Look for the file in the tree.
1
2
3
git cat-file -p 8d4f53e606d2061d5f4739c1d7835ed2b459ead8 | grep -i file.txt
100644 blob 16eff9690e76275603fd70b1aff5d26df5cdde19 file.txt
100644 blob 74ce4e42b9a29a016451f481e352545d309cd09e File.txt
If you find two or more files listed, your files file system is case-sensitive. These commands can be run on any Git repository.
Cause
Somewhere, this git repository may have been used on a system where the file system is case-sensitive and another one that is case-insensitive. On a case-sensitive system, the user was able to create File.txt and file.txt. Git allowed this to be committed because Git is case-sensitive by default. The system not showing the file is case insensitive. This means that only one file is allowed.
The Git repository may have been used on two different systems. One has a case-sensitive file system, while the other is case-insensitive. On the case-sensitive system, a user was able to create two files with the same name but different capitalization - File.txt and file.txt. Git allowed these files to be committed as it is case sensitive by default. However, on the case insensitive system, only one of these files is allowed to exist since the system does not differentiate between them.
Solution
Ensure that every clone using the repository has the following option enabled.:
1
2
3
4
# To confirm setting
git config core.ignorecase
# To set to false
git config core.ignorecase false
To fix existing files and directories, use git mv on the system that supports case sensitivity. For example, an ext3 file system on Linux, run the following commands to push the change upstream.
1
2
3
4
git mv -f test/One/File.txt test/one/file.txt.2
git add test/one/file.txt.2
git commit -m "fixed case sensitivity file."
git push
Was this helpful?