我该如何忽略git中的.pyc文件。 如果我放入.gitignore不起作用:我需要他们不追踪,不检查它的提交。忽略git仓库中的.pyc文件
回答
把它放在.gitignore
。但是从gitignore(5)
手册页:
· If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file). · Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a/in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
所以,要么指定完整路径到相应的*.pyc
项,或把它放在一个.gitignore
文件中的任何从库根领先的目录(含)。
为了避免让其他人感到困惑,Ignacio对手册页的解释是错误的。您不需要将* .pyc放在同一个目录中,只需将它放在父目录(或祖父母等)中即可。 – Godsmith 2015-06-02 08:21:22
@Godsmith:更正。 – 2015-06-02 08:23:22
在将*.pyc
放入.gitignore
之前,您可能已将其添加到存储库。
首先将它们从存储库中删除。库初始化之后
*.pyc
到.gitignore
文件在你的git仓库树的根文件夹:
这个问题每次都会让我知道 – ecoe 2013-10-13 18:54:12
你应该加一行。
由于ralphtheninja说,如果你忘了做这一点,事前,如果你只需要添加行至.gitignore
文件,所有以前犯.pyc
文件仍将被跟踪,所以你需要从删除库。
find . -name "*.pyc" -exec git rm -f "{}" \;
:
如果你是一个Linux系统(或“父母&儿子”像MacOSX的),你可以快速地与眼前这个,你需要从库的根执行一个命令行的做
这也就意味着:
从我目前的目录开始,查找其 名与扩展
.pyc
结束的所有文件,并通过文件名的命令git rm -f
后从混帐作为跟踪文件*.pyc
文件删除,提交此变更到仓库,然后你就可以在*.pyc
行最后添加到.gitignore
文件。
(改编自http://yuji.wordpress.com/2010/10/29/git-remove-all-pyc/)
感谢@Enrico的答案。
请注意,如果您使用的是virtualenv,您将在当前目录中包含多个.pyc
文件,这些文件将由他的find命令捕获。
例如:
./app.pyc
./lib/python2.7/_weakrefset.pyc
./lib/python2.7/abc.pyc
./lib/python2.7/codecs.pyc
./lib/python2.7/copy_reg.pyc
./lib/python2.7/site-packages/alembic/__init__.pyc
./lib/python2.7/site-packages/alembic/autogenerate/__init__.pyc
./lib/python2.7/site-packages/alembic/autogenerate/api.pyc
我想这是无害的删除所有文件,但如果你只是想删除你的主目录下的.pyc
文件,那么就去做
find "*.pyc" -exec git rm -f "{}" \;
这将从git存储库中删除app.pyc
文件。
- 1. 让Python忽略.pyc文件
- 2. 忽略文件占用git仓库中的空间
- 3. 在GIT仓库中标记临时忽略的文件
- 4. 在git仓库中意外忽略的文件
- 5. 如何忽略git仓库中的PyCharm配置文件?
- 6. 代码仓库中的环境文件与Git忽略
- 7. Atom不会忽略添加到忽略列表的* .pyc文件
- 8. 的Maven忽略了仓库
- 9. 在Git中忽略Git中的文件
- 10. 忽略`git log`中的git-svn文件
- 11. 我怎么能忽略git仓库中的bin和obj文件夹?
- 12. git仓库:如何忽略库的子文件夹(即其子文件夹的.git /)
- 13. git:忽略源文件中的文件
- 14. Rails忽略GIT的文件
- 15. 两个Git仓库的项目部分 - 如何忽略不同的文件?
- 16. Unity Git - 忽略库
- 17. 添加后从Git仓库中忽略目录
- 18. 保存文件的Git仓库,而忽略本地修改/删除
- 19. 的Git忽略不忽略指定的文件夹/文件
- 20. 的Git忽略不忽略一个文件,但所有文件
- 21. Yii2和Git忽略文件
- 22. git意外忽略文件
- 23. 忽略Git .Net文件
- 24. Git不忽略tmp文件
- 25. git忽略远程文件
- 26. Git忽略这种文件?
- 27. Git本地忽略文件
- 28. Git - 完全忽略文件
- 29. git GUI忽略.gitignore文件?
- 30. 设置git忽略文件
.gitignore应该工作。你能否提供你在.gitignore中放入的行的副本来尝试解决这个问题? – 2011-04-05 11:47:46