如何在Windows上使用msysgit忽略Git中的目录或文件夹?
当前回答
如果您想维护一个文件夹而不是其中的文件,只需在文件夹中放置一个“.gitignore”文件,其中包含“*”作为内容。此文件将使Git忽略存储库中的所有内容。但是.gitignore将包含在您的存储库中。
$ git add path/to/folder/.gitignore
如果您添加了一个空文件夹,则会收到此消息(.gitignore是一个隐藏文件)
The following paths are ignored by one of your .gitignore files:
path/to/folder/.gitignore
Use -f if you really want to add them.
fatal: no files added
因此,使用“-f”强制添加:
$ git add path/to/folder/.gitignore -f
其他回答
若要忽略整个目录,请在其中放置.gitignore的“*”。
例如
示例系统
/root/
.gitignore
/dirA/
someFile1.txt
someFile2.txt
/dirB/
.gitignore
someFile3.txt
someFile4.txt
Goal
忽略dirB的内容/
顶级(/root/.gitignore)
你可以在这里“dirB/”
忽略的目录(/root/dirB/.gitignore)
或者你可以在这里“*”
Git在文件系统的每一步都监视gitignore。所以这里我选择dirB/.gitignore作为“*”来忽略dirB/,包括其中的所有文件和子磁盘。
多恩☺️
默认情况下,当文件名为.gitignore.txt时,Windows资源管理器将显示.gitignore。
Git不会使用.gitignore.txt
您不能将文件重命名为.gitignore,因为Windows资源管理器认为它是一个没有名称的gitignore类型的文件。
非命令行解决方案:
You can rename a file to ".gitignore.", and it will create ".gitignore"
要指示Git忽略某些文件或文件夹,必须创建.gitignore文件。
但在Windows资源管理器中,您必须提供文件的名称。您无法创建仅具有扩展名的文件。诀窍是创建一个空文本文件,然后转到命令提示符,将文件名更改为.gitignore:
ren "New Text Document.txt" .gitignore
现在用您最喜欢的文本编辑器打开文件,并添加您希望忽略的文件/文件夹名称。也可以使用通配符,如*.txt。
如果您想维护一个文件夹而不是其中的文件,只需在文件夹中放置一个“.gitignore”文件,其中包含“*”作为内容。此文件将使Git忽略存储库中的所有内容。但是.gitignore将包含在您的存储库中。
$ git add path/to/folder/.gitignore
如果您添加了一个空文件夹,则会收到此消息(.gitignore是一个隐藏文件)
The following paths are ignored by one of your .gitignore files:
path/to/folder/.gitignore
Use -f if you really want to add them.
fatal: no files added
因此,使用“-f”强制添加:
$ git add path/to/folder/.gitignore -f
我在Windows资源管理器中使用创建文件时遇到一些问题。在开始时。
解决方法是进入commandshell并使用“edit”创建一个新文件。