gpt4 book ai didi

git - 无法让 Git 询问是否删除已删除的文件

转载 作者:太空狗 更新时间:2023-10-29 14:34:57 24 4
gpt4 key购买 nike

假设您有一个文件已提交到您的 Git 存储库中。

您只需删除文件

rm file

尽管您没有已删除的文件,但它仍保留在您的 Git 存储库中。

我的旧 Git 向我提示说在类似情况下你不能在 git add/rm 文件之前提交。我希望恢复相同的行为。

如果不首先解决文件存在的问题,你怎么能让 Git 不允许你提交

最佳答案

关于使用:

$ git commit -a

来自 git commit manual页:

The command git commit -a first looks at your working tree, notices that you have modified hello.c and removed goodbye.c, and performs necessary git add and git rm for you.


如果您不想要自动解决方案,而只想收到警告,则可以使用“pre-commit hook”。

 chmod a+x .git/hooks/pre-commit

该脚本将测试的输出

 git ls-files -d

并警告你有关已删除(但不是'git rm'ed)文件

关于git - 无法让 Git 询问是否删除已删除的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1061010/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com