我有一个项目,在开发时,我必须将chmod文件的模式更改为777,但在主库中不应更改。

Git拿起了chmod-R777。并将所有文件标记为已更改。有没有办法让Git忽略对文件所做的模式更改?


当前回答

添加到Greg Hewgill答案(使用core.fileMode配置变量):

您可以使用git更新索引(“gitadd”的低级版本)的--chmod=(-|+)x选项来更改索引中的执行权限,如果您使用“gitcommit”(而不是“gitcommit-a”),将从中获取执行权限。

其他回答

这可能有效:git-config-core.fileMode false

撤消工作树中的模式更改:

git diff --summary | grep --color 'mode change 100755 => 100644' | cut -d' ' -f7- | xargs -d'\n' chmod +x
git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | xargs -d'\n' chmod -x

或以明吉计

git diff --summary | grep  'mode change 100755 => 100644' | cut -d' ' -f7- | xargs -e'\n' chmod +x
git diff --summary | grep  'mode change 100644 => 100755' | cut -d' ' -f7- | xargs -e'\n' chmod -x

或在BSD/macOS中

git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7- | tr '\n' '\0' | xargs -0 chmod -x
git diff --summary | grep --color 'mode change 100755 => 100644' | cut -d' ' -f7- | tr '\n' '\0' | xargs -0 chmod -x

这对我有用:

find . -type f -exec chmod a-x {} \;

或相反,取决于您的操作系统

find . -type f -exec chmod a+x {} \;

简单的解决方案:

在项目文件夹中单击此简单命令(它不会删除原始更改)。。。它只会删除在您更改项目文件夹权限时所做的更改

命令如下:

git-config-core.fileMode false

为什么修改这些不必要的文件:因为您已更改项目文件夹权限带着赞扬sudo chmod-R 777/您的项目文件夹

你什么时候检查你没有做的更改?您在使用gitdiff文件名时发现如下

old mode 100644
new mode 100755

If

git config --global core.filemode false

不适用于您,请手动执行:

cd into yourLovelyProject folder

cd到.git文件夹:

cd .git

编辑配置文件:

nano config

将true更改为false

[core]
        repositoryformatversion = 0
        filemode = true

->

[core]
        repositoryformatversion = 0
        filemode = false

保存,退出,转到上层文件夹:

cd ..

勒紧吉特

git init

你完蛋了!