我刚刚在我的新项目的根上做了一个git初始化。
然后我创建了一个.gitignore文件。
现在,当我输入git status时,.gitignore文件出现在未跟踪文件列表中。为什么呢?
我刚刚在我的新项目的根上做了一个git初始化。
然后我创建了一个.gitignore文件。
现在,当我输入git status时,.gitignore文件出现在未跟踪文件列表中。为什么呢?
当前回答
以防别人和我们有同样的痛苦。 我们想要排除一个已经提交的文件。
这篇文章更有用: 使用.git/info/exclude太晚了
具体来说,你需要忽略一个文件实际上是使用命令git remove 参见git rm (http://www.kernel.org/pub/software/scm/git/docs/git-rm.html)
你通过去测试它
Git rm——dry-run *.log (如果你说想要排除所有日志文件)
这将输出如果运行它将被排除的内容。
then
你通过运行它
Git rm *.log (或任何你想要的文件名路径/表达式)
然后在.gitignore文件中添加*.log行。
其他回答
.gitignore是关于忽略其他文件。Git是关于文件的,所以这是关于忽略文件的。然而,当git处理文件时,这个文件需要作为列出其他文件名的机制。
如果它被称为.the_list_of_ignored_files,可能会更明显一些。
一个类比是你不想做的待办事项列表。除非你把它们列在某种“待办事项”清单上,否则你不会知道它们。
首先,正如许多人已经说过的,Git应该跟踪你的.gitignore(因此不应该忽略它)。让我来解释一下原因。
(TL;DR:提交.gitignore文件,并使用全局的.gitignore来忽略由IDE或操作系统创建的文件)
您可能已经知道,Git是一个分布式版本控制系统。这意味着它允许您在不同的版本之间来回切换(即使开发已经分散到不同的分支),它还允许多个开发人员在同一个项目上工作。
Although tracking your .gitignore also has benefits when you switch between snapshots, the most important reason for committing it is that you'll want to share the file with other developers who are working on the same project. By committing the file into Git, other contributers will automatically get the .gitignore file when they clone the repository, so they won't have to worry about accidentally committing a file that shouldn't be committed (such as log files, cache directories, database credentials, etc.). And if at some point the project's .gitignore is updated, they can simply pull in those changes instead of having to edit the file manually.
当然,会有一些文件和文件夹您想要忽略,但这是特定于您的,并不适用于其他开发人员。但是,这些不应该出现在项目的.gitignore中。还有两个地方可以忽略文件和文件夹:
Files and folders that are created by your operating system or IDE should be placed in a global .gitignore. The benefit is that this .gitignore is applied to all repositories on your computer, so you don't have to repeat this for every repository. And it's not shared with other developers, since they might be using a different operating system and/or IDE. Files that don't belong in the project's .gitignore, nor in the global .gitignore, can be ignored using explicit repository excludes in your_project_directory/.git/info/exclude. This file will not be shared with other developers, and is specific for that single repository
如果有人已经在你的回购中添加了.gitignore,但你想对它做一些更改,并忽略这些更改,请执行以下操作:
Git update-index——assume-unchanged .gitignore
源。
我认为在某些情况下,忽略.gitignore是非常有用的。例如,当您有多个团队或一个大型团队在同一个代码库上工作时。在这种情况下,你需要有一些约定,其中一个约定是关于git回购时忽略的内容。它通常是关于忽略IDE或OS创建的文件和目录,一些生成的日志等。
然而,有一种力量倾向于对.gitignore文件进行非常规的更改。.gitignore文件可以被不负责任的人、错误地、被使用的工具或在其他情况下进一步更改。
为了有一个反作用力,我们可以这样做:
首字母。gitignore应该反映团队的惯例, 在它被压入之后,.gitignore应该通过添加.gitignore条目来确保安全,并再次压入该更改。.gitignore文件以这种方式被“密封”。
“密封的”.gitignore文件可以在本地进行更改,而无需将更改者传播给团队的其他成员。然而,如果一个变更在整个团队中得到了广泛的同意,那么就有可能“打开”它,改变它,然后再“密封”它。那不可能是错误的,只能是有意的。
可悲的是,你不能百分之百地保护自己不做蠢事,但这样做你已经尽了一切努力来防止蠢事发生。
如果你的团队规模相对较小,但拥有非常优秀的专业人员,那么这就不重要了,但即使是那些人也会因为少担心一件事而感激不尽。
当你不能对基础设施设置做任何事情时,使用.git/info/exclude很酷,只是覆盖你自己的一个**以免出错。
从正确和错误的角度来看,我赞成在。gitignore文件中加入。gitignore条目,让每个人都可以自由地在本地做任何他们想做的事情,但不侵犯他人。
以防别人和我们有同样的痛苦。 我们想要排除一个已经提交的文件。
这篇文章更有用: 使用.git/info/exclude太晚了
具体来说,你需要忽略一个文件实际上是使用命令git remove 参见git rm (http://www.kernel.org/pub/software/scm/git/docs/git-rm.html)
你通过去测试它
Git rm——dry-run *.log (如果你说想要排除所有日志文件)
这将输出如果运行它将被排除的内容。
then
你通过运行它
Git rm *.log (或任何你想要的文件名路径/表达式)
然后在.gitignore文件中添加*.log行。