Git diff 报告本地更改“旧模式”; /“新模式”
有 2 台机器,A 和 B。并且有 2 个分支,p16 和 c2。
A 有一个 ext3 文件系统,但在 B 上,存档位于带有 vfat 的 truecrypt 驱动器上,挂载显示 rw,uid=1000,gid=1000,umask=077
A 已使用 sshfs 将 B 的目录树链接到其目录树中,然后A 使用文件系统推送到 B 的 p16 中。
现在存在一些权限问题:
B$ git status
# On branch p16
nothing to commit (working directory clean)
B$ git checkout c2
Switched to branch 'c2'
B$ git checkout p16
error: You have local changes to 'help.txt'; cannot switch branches.
git diff 现在向我显示所有文件的更改模式:
B$git diff
diff --git a/help.txtt b/help.txt
old mode 100644
new mode 100755
diff --git a/169.txt b/169.txt
old mode 100644
new mode 100755
...
(a list with all files having their mode changed follows)
...
我猜问题是本地文件系统是 vfat truecrypt 容器,并且文件系统不允许其他机器期望的权限。
有什么想法可以更好地将两台机器与不同的文件系统链接起来吗?
There are 2 machines, A and B. And there are 2 branches, p16 and c2.
A has an ext3 filesystem, but on B the archive lives on a truecrypt drive with vfat, mount shows rw,uid=1000,gid=1000,umask=077
A has linked the directory tree of B into its directory tree using sshfs and then A pushed into B's p16 using the filesystem.
Now there are some permission problems:
B$ git status
# On branch p16
nothing to commit (working directory clean)
B$ git checkout c2
Switched to branch 'c2'
B$ git checkout p16
error: You have local changes to 'help.txt'; cannot switch branches.
git diff shows me a changed mode for all files now:
B$git diff
diff --git a/help.txtt b/help.txt
old mode 100644
new mode 100755
diff --git a/169.txt b/169.txt
old mode 100644
new mode 100755
...
(a list with all files having their mode changed follows)
...
I guess the problem is that the local filesystem is a vfat truecrypt container and the filesystem does not allow the permissions that the other machine expects.
Any ideas how I can better link the 2 machines with different filesystems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果操作系统的文件权限在该位置未正常工作,则使用 git 时可能会出现此类问题。例如,当安装外部文件系统时。
meagar 在他对上述问题的评论中指出了解决方案:
只需确保您在 .git/config 中有一行(在
[core]
部分内),这将告诉 git 忽略可执行文件它跟踪的文件的位。
执行相同操作的另一种方法是转到终端中 git 存储库的根目录并键入:
请注意,有时需要更改此设置,但否则最好保留默认行为。在许多情况下,git 正确跟踪文件权限非常重要,这样您的项目才能正常工作。
Such problems using git can occur, if the file permissions of the operating system are not functioning as they should in that location. For example, when foreign filesystems are mounted.
The solution was pointed out by meagar in his comment on the question above:
Just make sure you have (within the
[core]
section) a linein .git/config which will tell git to ignore the executable bit for files it's tracking.
Another way of doing the same thing would be to go to the root directory of the git repo in the terminal and type:
Note that changing this setting is occasionally necessary, but otherwise it is better to keep the default behaviour. It's important in many cases for git to track file permissions correctly, so your project can work as it should.
我的 Ubuntu 安装已损坏,我必须完整安装 22.04 (Jammy Jellyfish)。
我备份了大量的 git 存储库(所有类型的项目,C#、HTML/JS 等),然后恢复它们。
我发现许多文件现在被设置为 755(可执行文件),而它们原来是 644。
因为没有其他任何更改,并且这些文件也被错误地设置为 exe。我只是使用以下命令再次检查了原始文件:
$ git checkout 。
这再次检查了主分支代码,文件模式恢复为 644。
My Ubuntu installation was corrupted and I had to do a complete install of 22.04 (Jammy Jellyfish).
I backed up a large number of git repos (projects of all types, C#, HTML/JS, etc.) and then restored them.
I discovered that many of the files were now set to 755 (executable) where they had been 644.
Because nothing else had changed and these files were improperly set to exe also. I simply checked out the original files again with the following command:
$ git checkout .
This checked out the main branch code again and the filemodes were restored to 644.