简体   繁体   English

在 windows 和 linux 之间使用相同的 git 存储库会导致额外的提交

[英]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).我有一个包含我的数据的 NTFS 分区,在两个操作系统之间共享(我是双引导 Linux 和 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.我有一个存储库,我一直在使用 Linux 一段时间,一切都很好,直到我尝试打开 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.如果我提交它们并从 Linux 打开存储库,我还有另一组未暂存的更改,并且循环继续。 When committing the changes that appear are a list of mode change [some #] => [some other #] [file name] for all tracked files.提交时出现的更改是所有跟踪文件的mode change [some #] => [some other #] [file name]

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. PS。 yes I am using Github to host the repo if this would make any difference.是的,如果这会有所不同,我正在使用 Github 来托管 repo。

Git stores information about the files in the working tree in the index. Git 将有关工作树中文件的信息存储在索引中。 Part of the data stored in the index is information about the device and inode of each file.存储在索引中的部分数据是有关每个文件的设备和 inode 的信息。 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.因此,跨操作系统共享工作树至少会导致在切换操作系统后运行git status或某些其他命令时需要重新读取所有文件。

In addition, Linux keeps executable permissions in the file system and Windows does not.此外,Linux 保留文件系统中的可执行权限,而 Windows 没有。 Because NTFS is a Windows file system, it does not maintain executable permissions.因为 NTFS 是一个 Windows 文件系统,所以它不维护可执行权限。 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. Linux 只能假设每个文件都是可执行的,因此您的提交会导致许多无法有效执行的文件被标记为可执行。 That's why the permissions seem to change.这就是权限似乎发生变化的原因。

In general, NTFS is not a good file system for Linux.一般来说,对于 Linux,NTFS 不是一个好的文件系统。 You are better off using a UDF file system, which will work both on Linux and Windows, but can keep and use POSIX permissions.你最好使用 UDF 文件系统,它可以在 Linux 和 Windows 上工作,但可以保留和使用 POSIX 权限。

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. UDF 可以使其正常工作并避免当前切换权限的问题,但它仍然不是推荐的解决方案,您应该避免它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM