1

I recently moved my programming stuff from local storage to a network storage. Since then Git doesn't work correctly anymore.

A typical scenario:
I change files. Now I want to stash the changes. I do git stash. Git rollbacks the changes. However the files are still marked as changed in git status. git diff -p shows

diff --git a/file.txt b/file.txt
old mode 100644
new mode 100755

I tried resetting the files by doing

  • git checkout -- file.txt
  • git reset --hard

but nothing works. The only way to get the working copy clean again is to chmod 644 file.txt.


The files lie on a Synology NAS. I am mounting by cifs to my Linux machine. I played with mount options noperm, file_mode, dir_mode but can't get it to work.

I read about git config core.filemode false but I am not sure whether this is the right thing to do here. I am afraid to damage my repository. Does Git save permissions info in the repository/index? Can I inspect this somehow? Maybe I already did something wrong with my recents commits.

theHacker
  • 3,984
  • 1
  • 19
  • 34

1 Answers1

1

You can't use Git across operating system boundaries, and possibly over Samba/CIFS, period, because it forces the file mask on new and modified files. See this 2013 discussion on Atlassian site. Couple of years ago I was hoping to use Windows SourceTree on a Git repo on my local dev server (Ubuntu VM instance on my local system) over a Samba map, but it was not to be. I still use the VM for the dev server as I find it terribly frustrating to work in Windows with environments that weren't designed to run in it, not to mention that the production environment is always Linux. The dev tools are way better on Windows, of course, so this is the "best of both worlds" solution for me (though the dev tools on Mac side are good, OSX would also not be 1:1 with the Linux production environment). So I use a Samba map and a good SSH client for everything else but Git write operations and visual Git diffs (i.e. reconciling rebase/merge conflicts) which are impossible to execute from Windows for the given reason. When a need arises to do a diff, I switch over to Linux GUI window, and execute the Linux GUI diff tool of choice there, and then the Linux permissions are handled correctly. Otherwise I operate Git on the command line with the SSH client. You can't have, for example, an IDE or a Windows Git client (like SourceTree) making commits into the repo over Samba/CIFS; it won't work correctly. For a visual Git client the new GitKraken is an excellent choice (it runs in Linux GUI).

In some cases you can circumvent the problem with file permissions by running the Git command while ignoring the file permissions (i.e. git -c core.fileMode=false), but I've found that to be messy and lead to trouble, so I only sometimes use it for non-write operations, such as git status, and have a Git alias defined for that purpose:

nfm = "!f(){ git -c core.fileMode=false $@; };f"

Then you can run a Git command with core.fileMode temporarily disabled, like so:

git nfm status

Added 2016-05-07T01:39:44Z:

Also see my related post in Superuser.

Community
  • 1
  • 1
Ville
  • 4,088
  • 2
  • 37
  • 38