git,不要在未跟踪文件列表中显示 *.pyc!

发布于 2024-07-14 12:48:00 字数 861 浏览 9 评论 0原文

执行时:

>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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

天赋异禀 2024-07-21 12:48:00

正如 gitignore 中提到的,git 有 3 个忽略文件

  • 应该进行版本控制并通过克隆分发到其他存储库的模式(即所有开发人员都希望忽略的文件)应该放入 .gitignore 文件

(这会处理所有时间:如果有人克隆您的存储库,它将获得 .gitignore 文件)

  • 特定于特定存储库但不需要与其他相关存储库共享的模式(例如,存储库内但特定于一个用户工作流程的辅助文件)应进入 $GIT_DIR/info/排除文件。

(对你的情况来说并不有趣)

  • 用户希望 git 在所有情况下都忽略的模式(例如,由用户选择的编辑器生成的备份或临时文件)通常会进入由 core.excludesfile 指定的文件< /strong> 在用户的 ~/.gitconfig 中。


(照顾所有项目,但不是所有时间,因为当克隆你的存储库时它不会被复制。)

“所有项目的所有时间”意味着例如一个自定义的用于创建新 git 项目的 shell,使用自定义 .gitignore 作为第一次提交的第一个文件部分...

As mentioned in gitignore, git has 3 ignore files:

  • Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that all developers will want to ignore) should go into a .gitignore file.

(that takes care of all time: if one clones your repo, it will get the .gitignore file)

  • Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.

(not interesting in your case)

  • 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.

(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...

沉溺在你眼里的海 2024-07-21 12:48:00

放入文件~/.gitignore

*.pyc

运行:

git config --global core.excludesfile ~/.gitignore

我同意@David Wolever 如果有的话,应谨慎使用此选项。

~/.gitignore(Windows 上的 "%HOME%\.gitignore")只是一种约定,您可以使用您喜欢的任何文件名,例如 "c: \docs\gitignore.txt”

Put in the file ~/.gitignore:

*.pyc

Run:

git config --global core.excludesfile ~/.gitignore

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".

星星的轨迹 2024-07-21 12:48:00
git config --global core.excludesfile "c:\program files\whatever\global_ignore.txt"

然后,添加

*.foo

到该文件。

git config --global core.excludesfile "c:\program files\whatever\global_ignore.txt"

Then, add

*.foo

to that file.

洒一地阳光 2024-07-21 12:48:00

忽略某些文件模式的另一种方法是:
将 *.pyc 添加到 .git/info/excludes 中,这是一种更简洁的方法。

Another way to ignore some file patterns is:
add *.pyc to .git/info/excludes, this is a much cleaner way.

甜尕妞 2024-07-21 12:48:00

添加

*.pyc

.gitignore 文件

并运行这

git config --global core.excludesfile .gitignore

对我有用

add

*.pyc

in .gitignore file

and run this

git config --global core.excludesfile .gitignore

which worked for me

静赏你的温柔 2024-07-21 12:48:00

如果我记得,有一种方法可以设置全局 .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>

始终不够爱げ你 2024-07-21 12:48:00

你不能将

*.pyc

添加到你的 .gitignore 中吗?

Couldn't you add

*.pyc

to your .gitignore?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文