I have a project in which I have to change the mode of files with chmod
to 777 while developing, but which should not change in the main repo.
我有一个项目,在开发过程中,我必须将chmod的文件模式更改为777,但在主要的repo中不应该更改。
Git picks up on chmod -R 777 .
and marks all files as changed. Is there a way to make Git ignore mode changes that have been made to files?
Git接收chmod - r777。并将所有文件标记为已更改。是否有一种方法可以让Git忽略对文件所做的更改?
10 个解决方案
#1
2991
Try:
试一试:
git config core.fileMode false
From git-config(1):
从git-config(1):
core.fileMode If false, the executable bit differences between the index and the working copy are ignored; useful on broken filesystems like FAT. See git-update-index(1). True by default.
The -c
flag can be used to set this option for one-off commands:
可以使用-c标志为一次性命令设置此选项:
git -c core.fileMode=false diff
And the --global
flag will make it be the default behavior for the logged in user.
全局标志将使它成为登录用户的默认行为。
git config --global core.fileMode false
Warning
core.fileMode
is not the best practice and should be used carefully. This setting only covers the executable bit of mode and never the read/write bits. In many cases you think you need this setting because you did something like chmod -R 777
, making all your files executable. But in most projects most files don't need and should not be executable for security reasons.
核心。fileMode并不是最好的做法,应该谨慎使用。该设置只覆盖可执行的模式,而不包括读/写位。在许多情况下,您认为您需要这个设置,因为您做了一些类似于chmod - r777的工作,使您的所有文件都可执行。但在大多数项目中,大多数文件不需要,也不应该出于安全考虑而执行。
The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:
解决这种情况的正确方法是分别处理文件夹和文件权限,比如:
find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write
If you do that, you'll never need to use core.fileMode
, except in very rare environment.
如果你这样做了,你就永远不需要使用core。除了在非常罕见的环境中。
#2
241
undo mode change in working tree:
工作树中的撤消模式更改:
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
Or in mingw-git
或者在mingw-git
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
#3
115
If you want to set this option for all of your repos, use the --global
option.
如果您想为所有的repos设置此选项,请使用-global选项。
git config --global core.filemode false
If this does not work you are probably using a newer version of git so try the --add
option.
如果这个方法不起作用,那么您可能正在使用一个新版本的git,所以尝试一下——添加选项。
git config --add --global core.filemode false
If you run it without the --global option and your working directory is not a repo, you'll get
如果你运行它,没有全局选项,你的工作目录不是一个repo,你会得到。
error: could not lock config file .git/config: No such file or directory
#4
62
If
如果
git config --global core.filemode false
does not work for you, do it manually:
不适合你,手动操作:
cd into yourLovelyProject folder
cd into .git folder:
cd .文件夹:
cd .git
edit the config file:
编辑配置文件:
nano config
change true to false
改变真的,假的
[core]
repositoryformatversion = 0
filemode = true
->
- >
[core]
repositoryformatversion = 0
filemode = false
save, exit, go to upper folder:
保存,退出,到上文件夹:
cd ..
reinit the git
reinit git
git init
you are done!
你做的!
#5
48
Adding to Greg Hewgill answer (of using core.fileMode
config variable):
加入格雷格·休吉尔的回答(使用核心)。fileMode配置变量):
You can use --chmod=(-|+)x
option of git update-index (low-level version of "git add") to change execute permissions in the index, from where it would be picked up if you use "git commit" (and not "git commit -a").
您可以使用-chmod=(-|+)x选项的git update-index(低级版本的“git add”)来更改索引中的执行权限,如果您使用“git commit”(而不是“git commit -a”),则会在该索引中获取它。
#6
31
You can configure it globally:
您可以在全球配置它:
git config --global core.filemode false
git配置——全球核心。filemode假
If the above doesn't work for you, the reason might be your local configuration overrides the global configuration.
如果上述方法对您不起作用,原因可能是您的本地配置覆盖了全局配置。
Remove your local configuration to make the global configuration take effect:
删除本地配置,使全局配置生效:
git config --unset core.filemode
git配置,设置core.filemode
Alternatively, you could change your local configuration to the right value:
或者,您可以将您的本地配置更改为正确的值:
git config core.filemode false
git配置核心。filemode假
#7
14
If you want to set filemode to false in config files recursively (including submodules) : find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'
如果您想要在配置文件中以递归的方式(包括子模块)设置filemode为false,请找到-name config | xargs sed -i -e 's/filemode = true/filemode = false/'
#8
14
By definining the following alias (in ~/.gitconfig) you can easily temporarily disable the fileMode per git command:
通过定义以下别名(在~/.gitconfig中),您可以轻松地暂时禁用每个git命令的fileMode:
nfm = "!f(){ git -c core.fileMode=false $@; };f"
When this alias is prefixed to the git command, the file mode changes won't show up with commands that would otherwise show them. For example:
当这个别名被预先固定到git命令时,文件模式更改将不会显示其他显示它们的命令。例如:
git nfm status
#9
14
If you have used chmod command already then check the difference of file, It shows previous file mode and current file mode such as:
如果您已经使用了chmod命令,然后检查文件的差异,它显示了以前的文件模式和当前文件模式,例如:
new mode : 755
新模式:755
old mode : 644
旧模式:644
set old mode of all files using below command
使用下面的命令设置所有文件的旧模式。
sudo chmod 644 .
sudo chmod 644。
now set core.fileMode to false in config file either using command or manually.
现在设置的核心。在配置文件中,fileMode可以使用命令或手动执行。
git config core.fileMode false
then apply chmod command to change the permissions of all files such as
然后应用chmod命令来更改所有文件的权限,比如。
sudo chmod 755 .
and again set core.fileMode to true.
一次又一次的核心。fileMode为true。
git config core.fileMode true
For best practises don't Keep core.fileMode false always.
因为最好的练习不能保持核心。fileMode假总是。
#10
1
Simple solution:
简单的解决方案:
Hit this Simple commend in project Folder(it won`t remove your original changes) ...it will only remove changes what had been done while you changed project folder permission
在项目文件夹中点击这个简单的推荐(它不会删除您的原始更改)…它只会删除在您更改项目文件夹权限时所做的更改。
commend is below:
赞扬是以下:
git config core.fileMode false
git配置核心。fileMode假
Why this all unnecessary file get modified: because you have changed the project folder permissions with commend sudo chmod -R 777 ./yourProjectFolder
为什么这一切不必要的文件被修改:因为你已经修改了项目文件夹的权限和推荐sudo chmod -R 777。/你的projectfolder ?
when will you check changes what not you did? you found like below while using git diff filename
什么时候你会检查你所做的改变呢?您在使用git diff文件名时发现如下。
#1
2991
Try:
试一试:
git config core.fileMode false
From git-config(1):
从git-config(1):
core.fileMode If false, the executable bit differences between the index and the working copy are ignored; useful on broken filesystems like FAT. See git-update-index(1). True by default.
The -c
flag can be used to set this option for one-off commands:
可以使用-c标志为一次性命令设置此选项:
git -c core.fileMode=false diff
And the --global
flag will make it be the default behavior for the logged in user.
全局标志将使它成为登录用户的默认行为。
git config --global core.fileMode false
Warning
core.fileMode
is not the best practice and should be used carefully. This setting only covers the executable bit of mode and never the read/write bits. In many cases you think you need this setting because you did something like chmod -R 777
, making all your files executable. But in most projects most files don't need and should not be executable for security reasons.
核心。fileMode并不是最好的做法,应该谨慎使用。该设置只覆盖可执行的模式,而不包括读/写位。在许多情况下,您认为您需要这个设置,因为您做了一些类似于chmod - r777的工作,使您的所有文件都可执行。但在大多数项目中,大多数文件不需要,也不应该出于安全考虑而执行。
The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:
解决这种情况的正确方法是分别处理文件夹和文件权限,比如:
find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write
If you do that, you'll never need to use core.fileMode
, except in very rare environment.
如果你这样做了,你就永远不需要使用core。除了在非常罕见的环境中。
#2
241
undo mode change in working tree:
工作树中的撤消模式更改:
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
Or in mingw-git
或者在mingw-git
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
#3
115
If you want to set this option for all of your repos, use the --global
option.
如果您想为所有的repos设置此选项,请使用-global选项。
git config --global core.filemode false
If this does not work you are probably using a newer version of git so try the --add
option.
如果这个方法不起作用,那么您可能正在使用一个新版本的git,所以尝试一下——添加选项。
git config --add --global core.filemode false
If you run it without the --global option and your working directory is not a repo, you'll get
如果你运行它,没有全局选项,你的工作目录不是一个repo,你会得到。
error: could not lock config file .git/config: No such file or directory
#4
62
If
如果
git config --global core.filemode false
does not work for you, do it manually:
不适合你,手动操作:
cd into yourLovelyProject folder
cd into .git folder:
cd .文件夹:
cd .git
edit the config file:
编辑配置文件:
nano config
change true to false
改变真的,假的
[core]
repositoryformatversion = 0
filemode = true
->
- >
[core]
repositoryformatversion = 0
filemode = false
save, exit, go to upper folder:
保存,退出,到上文件夹:
cd ..
reinit the git
reinit git
git init
you are done!
你做的!
#5
48
Adding to Greg Hewgill answer (of using core.fileMode
config variable):
加入格雷格·休吉尔的回答(使用核心)。fileMode配置变量):
You can use --chmod=(-|+)x
option of git update-index (low-level version of "git add") to change execute permissions in the index, from where it would be picked up if you use "git commit" (and not "git commit -a").
您可以使用-chmod=(-|+)x选项的git update-index(低级版本的“git add”)来更改索引中的执行权限,如果您使用“git commit”(而不是“git commit -a”),则会在该索引中获取它。
#6
31
You can configure it globally:
您可以在全球配置它:
git config --global core.filemode false
git配置——全球核心。filemode假
If the above doesn't work for you, the reason might be your local configuration overrides the global configuration.
如果上述方法对您不起作用,原因可能是您的本地配置覆盖了全局配置。
Remove your local configuration to make the global configuration take effect:
删除本地配置,使全局配置生效:
git config --unset core.filemode
git配置,设置core.filemode
Alternatively, you could change your local configuration to the right value:
或者,您可以将您的本地配置更改为正确的值:
git config core.filemode false
git配置核心。filemode假
#7
14
If you want to set filemode to false in config files recursively (including submodules) : find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'
如果您想要在配置文件中以递归的方式(包括子模块)设置filemode为false,请找到-name config | xargs sed -i -e 's/filemode = true/filemode = false/'
#8
14
By definining the following alias (in ~/.gitconfig) you can easily temporarily disable the fileMode per git command:
通过定义以下别名(在~/.gitconfig中),您可以轻松地暂时禁用每个git命令的fileMode:
nfm = "!f(){ git -c core.fileMode=false $@; };f"
When this alias is prefixed to the git command, the file mode changes won't show up with commands that would otherwise show them. For example:
当这个别名被预先固定到git命令时,文件模式更改将不会显示其他显示它们的命令。例如:
git nfm status
#9
14
If you have used chmod command already then check the difference of file, It shows previous file mode and current file mode such as:
如果您已经使用了chmod命令,然后检查文件的差异,它显示了以前的文件模式和当前文件模式,例如:
new mode : 755
新模式:755
old mode : 644
旧模式:644
set old mode of all files using below command
使用下面的命令设置所有文件的旧模式。
sudo chmod 644 .
sudo chmod 644。
now set core.fileMode to false in config file either using command or manually.
现在设置的核心。在配置文件中,fileMode可以使用命令或手动执行。
git config core.fileMode false
then apply chmod command to change the permissions of all files such as
然后应用chmod命令来更改所有文件的权限,比如。
sudo chmod 755 .
and again set core.fileMode to true.
一次又一次的核心。fileMode为true。
git config core.fileMode true
For best practises don't Keep core.fileMode false always.
因为最好的练习不能保持核心。fileMode假总是。
#10
1
Simple solution:
简单的解决方案:
Hit this Simple commend in project Folder(it won`t remove your original changes) ...it will only remove changes what had been done while you changed project folder permission
在项目文件夹中点击这个简单的推荐(它不会删除您的原始更改)…它只会删除在您更改项目文件夹权限时所做的更改。
commend is below:
赞扬是以下:
git config core.fileMode false
git配置核心。fileMode假
Why this all unnecessary file get modified: because you have changed the project folder permissions with commend sudo chmod -R 777 ./yourProjectFolder
为什么这一切不必要的文件被修改:因为你已经修改了项目文件夹的权限和推荐sudo chmod -R 777。/你的projectfolder ?
when will you check changes what not you did? you found like below while using git diff filename
什么时候你会检查你所做的改变呢?您在使用git diff文件名时发现如下。