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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/640449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:15:22  来源:igfitidea点击:

git, don't show me *.pyc in the list of untracked files!

gitversion-controlignore

提问by hasen

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.

它在“未跟踪的文件”下显示了一个很大的 .pyc 文件列表。我不希望它显示这些,因为它会增加噪音。

In other words, how do I make git ignore .pyc files all the time and for all projects?

换句话说,我如何让 git 一直忽略所有项目的 .pyc 文件?

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.

我不是在寻求一种将我忽略的文件传播给其他人的方法,我的意思只是“对于所有项目”,这意味着我不想将每个新项目配置为忽略 .pyc 文件。

UPDATE

更新

I should add that I'm working on windows, and my git is msysgit

我应该补充一点,我在 Windows 上工作,我的 git 是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.

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

Is .gitconfig a file or a folder? I don't have such a thing in my home directory (C:\users\<myusername>\)

.gitconfig 是文件还是文件夹?我的主目录中没有这样的东西 ( C:\users\<myusername>\)

UPDATE2

更新2

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

并将 *.pyc 放入 c:\git\ignore_files.txt

采纳答案by Bombe

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

Then, add

然后加

*.foo

to that file.

到那个文件。

回答by VonC

As mentioned in gitignore, git has 3 ignore files:

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

  • 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.
  • 应该受版本控制并通过克隆分发到其他存储库的模式(即所有开发人员都希望忽略的文件)应该放入.gitignore file.

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

(这会照顾所有时间:如果克隆您的仓库,它将获得 .gitignore 文件)

  • 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.
  • 特定于特定存储库但不需要与其他相关存储库共享的模式(例如,位于存储库内但特定于一个用户工作流的辅助文件)应进入 $GIT_DIR/info/exclude 文件。

(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.excludesfilein the user's ~/.gitconfig.
  • 用户希望 git 在所有情况下忽略的模式(例如,由用户选择的编辑器生成的备份或临时文件)通常会放入 .git 文件中指定的文件core.excludesfileuser's ~/.gitconfig

(takes cares of all projects, but not all timesince 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...

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

回答by jfs

Put in the file ~/.gitignore:

放入文件~/.gitignore

*.pyc

Run:

跑:

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

I agree with @David Woleverthis option should be used with caution if ever.

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

The ~/.gitignore("%HOME%\.gitignore"on Windows) is just a convention you can use any filename you like e.g., "c:\docs\gitignore.txt".

~/.gitignore"%HOME%\.gitignore"在Windows上)就是你可以使用任何文件名你喜欢如约定"c:\docs\gitignore.txt"

回答by demoslam

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

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

回答by Arun G

add

添加

*.pyc

in .gitignore file

在 .gitignore 文件中

and run this

并运行这个

git config --global core.excludesfile .gitignore

which worked for me

这对我有用

回答by David Wolever

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

如果我记得,有一种方法可以设置全局 .gitignore ......但问题是你不能与其他人共享它(也就是说,其他人拉你的代码会看到 .pyc 文件)。

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.

因此,恕我直言,最好将它添加到您开始的每个项目的 .gitignore 中。正是因为这个原因,我保留了一个 .gitignore 股票。

<flamebait>
Or you could switch to bzr, which comes with a sensible default list of things to ignore ^_^
</flamebait>

<flamebait>
或者你可以切换到 bzr,它带有一个明智的默认列表,可以忽略 ^_^
</flamebait>

回答by Glen Solsberry

Couldn't you add

你不能添加吗

*.pyc

*.pyc

to your .gitignore?

到你的 .gitignore?