Git pre-commit hook:更改/添加文件 [英] Git pre-commit hook : changed/added files
问题描述
我在写一个预先提交的钩子。我想对所有扩展名为.php的文件运行 我需要获取正在执行的新文件/已更改文件的列表。删除的文件应该被排除。 我试过使用 这表明wt-status.c被修改,wt-status.h在暂存区(索引)中被删除。因此,仅检查未被删除的文件: 你将不得不跳过额外的箍环来处理空格中的文件名(-z选项用于git diff和一些更有趣的解析) I am writing a pre-commit hook. I want to run I need to obtain a list of new/changed files that are staged. deleted files should be excluded. I have tried using This indicates that wt-status.c was modified and wt-status.h was removed in the staging area (index). So, to check only files that weren't removed: You will have to jump through extra hoops to deal with filenames with spaces in though (-z option to git diff and some more interesting parsing) 这篇关于Git pre-commit hook:更改/添加文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! php -l </ code>。不过我被卡住了。
git diff
和 git ls-文件
,但我认为我需要在这里工作。
git diff --cached --name-status
会显示所执行的内容摘要,因此您可以轻松排除已移除的文件,例如:
M wt-status.c
D wt-status.h
steve @ aris:〜/ src / git< master> $ git diff --cached --name-status | awk'$ 1!=D{print $ 2}'
wt-status.c
wt-status.h
php -l
against all files with .php extension. However I am stuck.git diff
and git ls-files
, but I think I need a hand here.git diff --cached --name-status
will show a summary of what's staged, so you can easily exclude removed files, e.g.:M wt-status.c
D wt-status.h
steve@arise:~/src/git <master>$ git diff --cached --name-status | awk '$1 != "D" { print $2 }'
wt-status.c
wt-status.h