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.
精彩评论