开发者

Git diff reports local changes 'old mode' / 'new mode'

开发者 https://www.devze.com 2023-02-20 03:47 出处:网络
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

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 an开发者_高级运维d 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?


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 line

filemode=false

in .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:

git config core.filemode false

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.


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.

old mode 100644
new mode 100755

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号