Mar*_*tin 2188 git ignore chmod
我有一个项目,我必须chmod
在开发过程中将文件模式更改为777,但不应在主回购中更改.
Git选择chmod -R 777 .
并将所有文件标记为已更改.有没有办法让Git忽略对文件进行的模式更改?
Gre*_*ill 3626
尝试:
git config core.fileMode false
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)core.fileMode Tells Git if the executable bit of files in the working tree is to be honored. Some filesystems lose the executable bit when a file that is marked as executable is checked out, or checks out a non-executable file with executable bit on. git-clone(1) or git-init(1) probe the filesystem to see if it handles the executable bit correctly and this variable is automatically set as necessary. A repository, however, may be on a filesystem that handles the filemode correctly, and this variable is set to true when created, but later may be made accessible from another environment that loses the filemode (e.g. exporting ext4 via CIFS mount, visiting a Cygwin created repository with Git for Windows or Eclipse). In such a case it may be necessary to set this variable to false. See git-update-index(1). The default is true (when core.filemode is not specified in the config file).
该-c
标志可用于为一次性命令设置此选项:
git -c core.fileMode=false diff
Run Code Online (Sandbox Code Playgroud)
该--global
标志将使其成为登录用户的默认行为.
git config --global core.fileMode false
Run Code Online (Sandbox Code Playgroud)
git clone
不是最佳做法,应谨慎使用.此设置仅涵盖模式的可执行位,而不包括读/写位.在许多情况下,您认为您需要此设置,因为您执行了类似操作git init
,使所有文件都可执行.但是在大多数项目中,出于安全原因,大多数文件不需要也不应该是可执行的.
解决这种情况的正确方法是分别处理文件夹和文件权限,例如:
find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write
Run Code Online (Sandbox Code Playgroud)
如果你这样做,你将永远不需要使用core.fileMode
,除非在非常罕见的环境中.
yod*_*oda 268
在工作树中撤消模式更改:
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
Run Code Online (Sandbox Code Playgroud)
或者在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
Run Code Online (Sandbox Code Playgroud)
小智 131
如果要为所有存储库设置此选项,请使用该--global
选项.
git config --global core.filemode false
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,您可能正在使用更新版本的git,请尝试使用该--add
选项.
git config --add --global core.filemode false
Run Code Online (Sandbox Code Playgroud)
如果你在没有--global选项的情况下运行它并且你的工作目录不是repo,你就会得到
error: could not lock config file .git/config: No such file or directory
Run Code Online (Sandbox Code Playgroud)
Sin*_*dem 79
如果
git config --global core.filemode false
Run Code Online (Sandbox Code Playgroud)
不起作用,手动完成:
cd into yourLovelyProject folder
Run Code Online (Sandbox Code Playgroud)
cd进.git文件夹:
cd .git
Run Code Online (Sandbox Code Playgroud)
编辑配置文件:
nano config
Run Code Online (Sandbox Code Playgroud)
将true更改为false
[core]
repositoryformatversion = 0
filemode = true
Run Code Online (Sandbox Code Playgroud)
- >
[core]
repositoryformatversion = 0
filemode = false
Run Code Online (Sandbox Code Playgroud)
保存,退出,转到上层文件夹:
cd ..
Run Code Online (Sandbox Code Playgroud)
重新启动git
git init
Run Code Online (Sandbox Code Playgroud)
你完成了!
Jak*_*ski 51
添加到Greg Hewgill的答案(使用core.fileMode
配置变量):
您可以使用git update-index--chmod=(-|+)x
选项(低级版本的"git add")来更改索引中的执行权限,如果您使用"git commit"(而不是"git commit",则可以从中获取权限) ").
Tyl*_*ong 37
您可以全局配置它:
git config --global core.filemode false
如果上述方法不适合您,原因可能是您的本地配置会覆盖全局配置.
删除本地配置以使全局配置生效:
git config --unset core.filemode
或者,您可以将本地配置更改为正确的值:
git config core.filemode false
小智 21
如果你已经使用过chmod命令,那么检查文件的差异,它显示以前的文件模式和当前文件模式,例如:
新模式:755
旧模式:644
使用以下命令设置所有文件的旧模式
sudo chmod 644 .
现在使用命令或手动将配置文件中的core.fileMode设置为false.
git config core.fileMode false
Run Code Online (Sandbox Code Playgroud)
然后应用chmod命令来更改所有文件的权限,例如
sudo chmod 755 .
Run Code Online (Sandbox Code Playgroud)
并再次将core.fileMode设置为true.
git config core.fileMode true
Run Code Online (Sandbox Code Playgroud)
对于最佳实践,请不要始终将core.fileMode保留为false.
Vil*_*lle 17
通过定义以下别名(在〜/ .gitconfig中),您可以轻松地临时禁用fileMode per git命令:
[alias]
nfm = "!f(){ git -c core.fileMode=false $@; };f"
Run Code Online (Sandbox Code Playgroud)
当此别名以git命令作为前缀时,文件模式更改将不会显示将显示它们的命令.例如:
git nfm status
Run Code Online (Sandbox Code Playgroud)
dry*_*obs 13
如果要在递归的配置文件中将filemode设置为false(包括子模块):
find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'
简单的解决方案:
打这个简单的命令在项目文件夹(它不会删除你原来的变化) ......它只会移除变更已被做了,而你更改项目文件夹的权限
命令如下:
git 配置 core.fileMode 假
为什么所有不必要的文件都被修改: 因为您已经使用sudo chmod -R 777 ./yourProjectFolder更改了项目文件夹权限
你什么时候会检查你没有做的变化?您在使用git diff 文件名时发现如下所示
old mode 100644
new mode 100755
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
861957 次 |
最近记录: |