简体   繁体   中英

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 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

您可以使用git update-index --chmod=-x <files>直接修改索引,而不是使用chmod和readding。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM