gpt4 book ai didi

python - 在子文件夹中使用 .gitignore 和 *.pyc

转载 作者:太空狗 更新时间:2023-10-30 00:49:34 26 4
gpt4 key购买 nike

我看到在 python 3 中,我的应用程序的每个子文件夹中都有一个 __pycache__,当然也会在那里创建 *.pyc 文件。在我的应用程序根文件夹的 .gitignore 中,我可以简单地放置:

**/__pycache__
**/*.pyc

在所有 future 创建的子文件夹中忽略这些?或者我需要在每个子文件夹中放置一个 .gitignore 吗?

在相关说明中,我如何检查所有未跟踪(忽略)的内容。我试过“git status -u”,它没有显示 __pycache__ 或 .pyc 文件未被跟踪。

最佳答案

你不应该需要 **/:

 __pycache__/
*.pyc

这应该足够了。

例如参见 gitignore.io/python .
请注意添加尾随 / 以专门忽略文件夹的做法。

使用git check-ignore -v --afile(即I mentioned in Sept. 2013, with Git 1.8.2+)检查哪个规则忽略了一个文件。
如果文件夹已被跟踪:

git rm --cached -r __pycache__/

André Duarte添加 in the comments :

After adjusting gitignore, I had to do this for every file, so I call awk for help:

git status | grep pycache | awk '{print $3}' | xargs git reset HEAD

关于python - 在子文件夹中使用 .gitignore 和 *.pyc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587096/

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