git,不要在未跟踪文件列表中显示 *.pyc!
执行时:
>git status
它在“未跟踪文件”下显示了一个大的 .pyc 文件列表。 我不想让它显示这些,因为它会增加噪音。
换句话说,如何让 git 对于所有项目始终忽略 .pyc 文件?
编辑
我并不是在寻求一种将我忽略的文件传播给其他人的方法,我的意思只是“对于所有项目”,这意味着我不想将每个新项目配置为忽略 .pyc文件。
更新
我应该补充一点,我正在 Windows 上工作,我的 git 是 msysgit
用户希望 git 在所有情况下忽略的模式(例如,由用户选择的编辑器生成的备份或临时文件)通常会进入用户的 ~/.gitconfig 中 core.excludesfile 指定的文件中。
.gitconfig 是文件还是文件夹? 我的主目录中没有这样的东西 (C:\users\
)
UPDATE2
感谢大家的回复,
我通过以下方式解决了问题使用:
>git config --global core.excludesfile c:\git\ignore_files.txt
并将 *.pyc 放入 c:\git\ignore_files.txt
When doing:
>git status
It shows a big list of .pyc files under "untracked files". I don't want it to show these, as it adds noise.
In other words, how do I make git ignore .pyc files all the time and for all projects?
EDIT
I'm not asking for a way to spread my ignored files to other people, I really just mean "for all projects", meaning I don't want to configure each new project to ignore .pyc files.
UPDATE
I should add that I'm working on windows, and my git is msysgit
Patterns which a user wants git to ignore in all situations (e.g., backup or temporary files generated by the user's editor of choice) generally go into a file specified by core.excludesfile in the user's ~/.gitconfig.
Is .gitconfig a file or a folder? I don't have such a thing in my home directory (C:\users\<myusername>\
)
UPDATE2
Thanks everybody for the responses,
I solved the issues by using:
>git config --global core.excludesfile c:\git\ignore_files.txt
and putting *.pyc in c:\git\ignore_files.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
正如 gitignore 中提到的,git 有 3 个忽略文件:
(这会处理所有时间:如果有人克隆您的存储库,它将获得 .gitignore 文件)
(对你的情况来说并不有趣)
(照顾所有项目,但不是所有时间,因为当克隆你的存储库时它不会被复制。)
“所有项目的所有时间”意味着例如一个自定义的用于创建新 git 项目的 shell,使用自定义 .gitignore 作为第一次提交的第一个文件部分...
As mentioned in gitignore, git has 3 ignore files:
(that takes care of all time: if one clones your repo, it will get the .gitignore file)
(not interesting in your case)
(takes cares of all projects, but not all time since it is not replicated when one clones your repo.)
"All time for all projects" would means for instance a custom shell for creating new git projects, with a custom .gitignore as first file part of the first commit...
放入文件
~/.gitignore
:运行:
我同意@David Wolever 如果有的话,应谨慎使用此选项。
~/.gitignore
(Windows 上的"%HOME%\.gitignore"
)只是一种约定,您可以使用您喜欢的任何文件名,例如"c: \docs\gitignore.txt”
。Put in the file
~/.gitignore
:Run:
I agree with @David Wolever this option should be used with caution if ever.
The
~/.gitignore
("%HOME%\.gitignore"
on Windows) is just a convention you can use any filename you like e.g.,"c:\docs\gitignore.txt"
.然后,添加
到该文件。
Then, add
to that file.
忽略某些文件模式的另一种方法是:
将 *.pyc 添加到 .git/info/excludes 中,这是一种更简洁的方法。
Another way to ignore some file patterns is:
add *.pyc to .git/info/excludes, this is a much cleaner way.
添加
.gitignore 文件
并运行这
对我有用
add
in .gitignore file
and run this
which worked for me
如果我记得,有一种方法可以设置全局 .gitignore...但问题是您无法与其他人共享它(也就是说,拉取您代码的其他人将看到 .pyc 文件)。
因此,恕我直言,最好将其添加到您启动的每个项目的 .gitignore 中。 出于这个原因,我保留了一个库存 .gitignore。
<火焰诱饵>
或者你可以切换到 bzr,它带有一个合理的默认列表,其中包含要忽略的内容 ^_^
If I recall, there is a way to setup a global .gitignore... But the problem with that is you can't share it with other people (that is, other people who pull your code will see the .pyc files).
So, IMHO, it's better to just add it to the .gitignore for each project you start. I keep a stock .gitignore around for just that reason.
<flamebait>
Or you could switch to bzr, which comes with a sensible default list of things to ignore ^_^
</flamebait>
你不能将
*.pyc
添加到你的 .gitignore 中吗?
Couldn't you add
*.pyc
to your .gitignore?