开发者

git add hook / getting git to ignore file modes of new files

I'm working with a git repository on both windows and linux/mac. When I create new files on windows, or edit them in some text editors, the file mode is changed to 775. I can get git to ignore file mode changes with

git config core.filemode false

but I also want most new files to have mode 664 (not 775). The best I've come up with so开发者_Go百科 far is the pre-commit hook

git diff --cached --name-only | egrep -v '\.(bat|py|sh|exe)' | xargs -d"\n" chmod 664
git diff --cached --name-only | egrep -v '\.(bat|py|sh|exe)' | xargs -d"\n" git add

but this does the wrong thing if I've added a new file, then edited it again before commiting, and then commited without adding it. Is there a better way to do this, or something like a pre-add or post-add hook?

Edit: git diff --cached --name-only also gives me files that have been deleted, so what I really want is something like git diff --cached --name-only --diff-filter=ACMRTUXB


Instead of using chmod and readding, you can use git update-index --chmod=-x <files> to modify the index directly.


Take a look at git attributes. You can handle it there. Smudge/clean may be a way to deal with it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜