我有一个git结帐。所有的文件权限都不同于git认为它们应该是什么,因此它们都显示为修改。
没有触及文件的内容(只是想修改权限),我如何设置所有文件的权限,git认为他们应该是什么?
我有一个git结帐。所有的文件权限都不同于git认为它们应该是什么,因此它们都显示为修改。
没有触及文件的内容(只是想修改权限),我如何设置所有文件的权限,git认为他们应该是什么?
当前回答
谢谢@muhqu的精彩回答。在我的例子中,并不是所有的更改文件都更改了权限,这阻止了命令的工作。
$ git diff -p -R --no-ext-diff --no-color | grep -E "^(diff|(old|new) mode)" --color=never
diff --git b/file1 a/file1
diff --git b/file2 a/file2
old mode 100755
new mode 100644
$ git diff -p -R --no-ext-diff --no-color | grep -E "^(diff|(old|new) mode)" --color=never | git apply
warning: file1 has type 100644, expected 100755
然后补丁将停止,文件将保持不变。
如果有人有类似的问题,我通过调整命令来解决这个问题,只有权限更改文件:
grep -E "^old mode (100644|100755)" -B1 -A1
或者git别名
git config --global --add alias.permission-reset '!git diff -p -R --no-ext-diff --no-color | grep -E "^old mode (100644|100755)" -B1 -A1 --color=never | git apply'
其他回答
最简单的方法就是把权限改回来。正如@kroger指出的,git只跟踪可执行位。所以你可能只需要运行chmod -x文件名来修复它(或者如果需要的话+x)。
你也可以尝试一个前/后结帐挂钩。
参见:自定义Git - Git钩子
git diff -p \
| grep -E '^(diff|old mode|new mode)' \
| sed -e 's/^old/NEW/;s/^new/old/;s/^NEW/new/' \
| git apply
将工作在大多数情况下,但如果你有外部差异工具,如meld安装,你必须添加-no-ext-diff
git diff --no-ext-diff -p \
| grep -E '^(diff|old mode|new mode)' \
| sed -e 's/^old/NEW/;s/^new/old/;s/^NEW/new/' \
| git apply
在我的情况下需要什么
谢谢@muhqu的精彩回答。在我的例子中,并不是所有的更改文件都更改了权限,这阻止了命令的工作。
$ git diff -p -R --no-ext-diff --no-color | grep -E "^(diff|(old|new) mode)" --color=never
diff --git b/file1 a/file1
diff --git b/file2 a/file2
old mode 100755
new mode 100644
$ git diff -p -R --no-ext-diff --no-color | grep -E "^(diff|(old|new) mode)" --color=never | git apply
warning: file1 has type 100644, expected 100755
然后补丁将停止,文件将保持不变。
如果有人有类似的问题,我通过调整命令来解决这个问题,只有权限更改文件:
grep -E "^old mode (100644|100755)" -B1 -A1
或者git别名
git config --global --add alias.permission-reset '!git diff -p -R --no-ext-diff --no-color | grep -E "^old mode (100644|100755)" -B1 -A1 --color=never | git apply'
我在Windows上使用cygwin的git, git应用解决方案不适合我。这是我的解决方案,在每个文件上运行chmod来重置其权限。
#!/bin/bash
IFS=$'\n'
for c in `git diff -p |sed -n '/diff --git/{N;s/diff --git//g;s/\n/ /g;s# a/.* b/##g;s/old mode //g;s/\(.*\) 100\(.*\)/chmod \2 \1/g;p}'`
do
eval $c
done
unset IFS