6

I'm having a problem with Git which, according to everything I know about how Git works, should never happen.

I'm trying to clone a repository from Bitbucket, on a clean directory. Just after cloning, the project shows uncommited changes to the repository - git status shows several modified files. Those changes correspond to a pull request currently still awaiting revision and unmerged on said repository, by another developer.

The URL from which I clone has nothing that would indicate it's pointing to any specific commit or pull request, and the repository HEAD is in master. Furthermore, deleting the directory using rm -rf or even switching to a completely different directory and then cloning again reproduces the issue. My coworkers however can't reproduce the issue in their local machines.

All usual measures like git reset --hard or stashing changes just take me back to the repository as it was when cloned, including the uncommited changes I mentioned.

What could possibly be causing this weird behaviour?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kace91
  • 821
  • 1
  • 10
  • 23
  • 1
    Did you try this: https://stackoverflow.com/questions/5009096/files-showing-as-modified-directly-after-git-clone ? – Maroun Apr 23 '19 at 12:28
  • @Maroun The solutions in that thread don't help; however, it is very likely that my issue is related, since I am in fact using a mac and my colleagues' PR seems to consist only on switching uppercase and lowercase letters in several files. – kace91 Apr 23 '19 at 12:36
  • @kace91, in _files_ or file _names_? What OS are your colleagues using? – ChrisGPT was on strike Apr 23 '19 at 12:36
  • @Chris in files, filenames haven't changed as far as I can see. My colleagues all use either ubuntu or OSX - ubuntu in the case of the one who submitted the above mentioned PR – kace91 Apr 23 '19 at 12:40
  • Do you have any Git hooks configured? Run `git config --list --show-origin` and look for `core.hooksPath` or similar. If you don't see anything about hooks, is there anything else interesting in there? – ChrisGPT was on strike Apr 23 '19 at 13:04
  • @Chris No hooks, nor anything abnormal in there, except for file:.git/config core.ignorecase=true which was part of my attempt at fixing the problem, as seen in the link sent by Maroun (to no avail) – kace91 Apr 23 '19 at 15:25
  • 3
    Can you share the exact output of `git status` and `git branch -a`? – ChrisGPT was on strike Apr 23 '19 at 15:42
  • @Chris sure, here it is https://justpaste.it/386be – kace91 Apr 24 '19 at 07:50
  • My guess, looking at the pasted output, is that you have some unknown process running that's changing those files. Do you have any kind of Git hook (look at `.git/hooks/`), server that hot reloads, or other process running that could alter those files? I understand the concern for privacy, but other people understanding the purpose of those files to your application could help solve the problem. – Jake Worth Apr 24 '19 at 19:26
  • @JakeWorth, that was my thought to but if this is happening on a clone it won't be `.git/hooks` (since `.git/` won't exist yet) and [OP says there are no global hooks](https://stackoverflow.com/questions/55811151/is-git-bringing-uncommited-changes-on-clone?noredirect=1#comment98295941_55811151). – ChrisGPT was on strike Apr 24 '19 at 19:55
  • 1
    @JakeWorth the files aren't really anything weird, it's just a bunch of json files that are used as mock data. They contain no executable code and there is no external process modifying them, I downloaded on a personal macbook just in case and the same exact problem is present. I'm using git from a terminal so there is no chance of changes happening because an editor autoformatting or anything similar, and the changes are very specific to be caused by an automatic process - as I commented, they correspond to modifications in a different branch. – kace91 Apr 25 '19 at 08:42
  • 1
    "I downloaded on a personal macbook just in case and the same exact problem is present"—even weirder. What if you use a different _user_ on the same machine? And exactly what command are you running? – ChrisGPT was on strike Apr 25 '19 at 15:14
  • Ok, now I'm really curious! Would you be interested in trying something like this? https://stackoverflow.com/a/8319931/2112512 -- TL;DR `sudo fs_usage | grep your-file.json` ...what process is editing the file? – Jake Worth Apr 25 '19 at 16:31
  • Another long shot worth investigating: https://confluence.atlassian.com/bitbucketserverkb/git-status-shows-as-files-modified-directly-after-clones-943969037.html – Jake Worth Apr 26 '19 at 13:29

1 Answers1

1

One possible issue could be : the case sensitivity of your file system.

On your system : check if the settings for the filesystem you use are the same as your colleagues' -- is their main partition HFS+ ? or HFS+ with case sensitivity ? or some ext* format ?

On your repo : check if there are paths that differ only in casing (e.g : Readme.json and README.json in a same directory, or src/testdata/foo.json and src/TestData/foo.json)

You can check this on files reported as "modified" by git status : check if the file's and directories' names on the paths mentioned by git status are cased exactly as in what you see on your disk (ls in a terminal, or using the Finder).

You can view the content of a commit as stored by git using git ls-tree :

# view the content of the root of your repo :
git ls-tree --name-only HEAD

# view the content of directory 'src/demo' :
git ls-tree --name-only HEAD:src/demo

# view the complete list of files under a directory :
git ls-tree -r --name-only HEAD
git ls-tree -r --name-only HEAD:src/demo

HEAD means "the current commit", you can replace it with anything (a commit hash, a branch or tag name, HEAD~4, stash@{2} ... )


Here is a simple post giving an illustrative example of what can happen because of case sensitivity of the filesystem :

https://www.hanselman.com/blog/git-is-casesensitive-and-your-filesystem-may-not-be-weird-folder-merging-on-windows

LeGEC
  • 46,477
  • 5
  • 57
  • 104