Search code examples
linuxwindowsgitgithubversion-control

Using the same git repository between windows and linux results in an extra commit


I have an NTFS partition that contains my data, shared between two operating systems (I am dual booting Linux and Windows). I have a repository that I have been working on using Linux for some time and all was good, until I tried opening the repository on windows. I noticed that I had unstaged changes even though I didn't change anything. If I commit them and open the repository from Linux I have another set of unstaged changes and the cycle goes on. When committing the changes that appear are a list of mode change [some #] => [some other #] [file name] for all tracked files.

I have seen some people saying that it is not a good idea to share a repository between different operating systems but without saying why. Can someone explain why does this happen, and if it can be solved (without using a different repository if possible).

PS. yes I am using Github to host the repo if this would make any difference.


Solution

  • Git stores information about the files in the working tree in the index. Part of the data stored in the index is information about the device and inode of each file. This information differs based on the operating system, since different operating systems number their devices differently. Consequently, sharing a working tree across operating systems will, at the very least, result in all files needing to be re-read when running git status or certain other commands after having switched operating systems.

    In addition, Linux keeps executable permissions in the file system and Windows does not. Because NTFS is a Windows file system, it does not maintain executable permissions. Linux can only assume that every file is executable, and so your commits result in many files that could not be usefully executed being marked as executable. That's why the permissions seem to change.

    In general, NTFS is not a good file system for Linux. You are better off using a UDF file system, which will work both on Linux and Windows, but can keep and use POSIX permissions.

    As previously mentioned, you are going to have problems sharing a working tree across operating systems. UDF may make it functional and avoid the current problems with switching permissions, but it is still not a recommended solution and you should avoid it.