如何在Windows上使用msysgit忽略Git中的目录或文件夹?


当前回答

当其他一切都失败时,尝试编辑文件

/.git/info/exclude

并将您想要的目录添加到文件末尾,如下所示:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
assets/
compiled/

我将文件夹“assets”和“compiled”添加到要忽略的文件和目录列表中。

其他回答

如果您想维护一个文件夹而不是其中的文件,只需在文件夹中放置一个“.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”文件:

*
!.gitignore

这对我有用。

在Windows和Mac上,如果要忽略当前目录中名为Flower_Data_folder的文件夹,可以执行以下操作:

echo Flower_Data_Folder >> .gitignore

如果是名为data.txt的文件:

echo data.txt >> .gitignore

如果是类似“Data/passwords.txt”的路径

echo "Data/passwords.txt" >> .gitignore. 

当其他一切都失败时,尝试编辑文件

/.git/info/exclude

并将您想要的目录添加到文件末尾,如下所示:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
assets/
compiled/

我将文件夹“assets”和“compiled”添加到要忽略的文件和目录列表中。

默认情况下,当文件名为.gitignore.txt时,Windows资源管理器将显示.gitignore。

Git不会使用.gitignore.txt

您不能将文件重命名为.gitignore,因为Windows资源管理器认为它是一个没有名称的gitignore类型的文件。

非命令行解决方案:

You can rename a file to ".gitignore.", and it will create ".gitignore"