Files stuck in your local .git

Files stuck in your local .git

Published: 5/23/2018

There's one troublesome issue with SourceTree (or perhaps any other GUI program for .git management) - it never shows you the entire picture.

I got into a "kerfuffle" with a branch that wouldn't delete, wouldn't switch, couldn't stash, couldn't force checkout. Literally everything I tried had no effect whatsoever.

Source Tree was giving me nothing - it simply showed a list of files that had been "modified" without changing any of the code (even git status showed me precious little).

Img

This got me searching and thinking - what could change a file without changing any code? At first I thought meta data - I've obviously grabbed these new files from someone else - their machine must have stamped them or something? Stupid. If this was the case then it'd happen to every file, every time…

Permissions.

Yes, that's right - what can change a file without changing the code? Permissions. Stick that in a cracker.

To test this you can simply do a git diff <file> (you should really do this first - before trying to think too hard…)

This should give you the following result:

Img

Clear as day right? Old mode was 644 - new mode is now 755. A file permission change. Use ":q" to exit.

So how do we fix this? Well we could reset the file permissions for all the files but my guess is - the other colleague will not be too pleased about it.

Instead you can choose not to track file permission changes (just remember to perform them locally / remotely if required):

git config core.fileMode false (or true)

This will clear out your Source Tree and git status.