这是我的预提交钩子:
#!/bin/sh
echo "removing file.txt"
rm file.txt
exit 0
这是 git commit 的输出:
$ git commit -m "test"
removing file.txt
[master (root-commit) b82b2e1] test
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file.txt
为什么它识别 file.txt ?? 是因为它没有包含在 gitignore 中吗?
我不知道是什么,确切的说,你的意思是由动词承认,但这里的主要问题是,Git不会从使提交工作树。Git 从index提交。
当您git add file.txt
将 的内容file.txt
从工作树复制到索引中时。如果该文件file.txt
以前没有出现在索引中,现在它出现了。如果是在索引之前,旧索引内容,现在换成无论是在工作树file.txt
。
当您运行时git commit
,它会立即获取索引中的任何内容并将其转换为提交。在你的预提交钩子中,你修改了工作树,而不是索引——所以索引保持原样,文件进入提交。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句