如何在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”添加到要忽略的文件和目录列表中。
其他回答
要指示Git忽略某些文件或文件夹,必须创建.gitignore文件。
但在Windows资源管理器中,您必须提供文件的名称。您无法创建仅具有扩展名的文件。诀窍是创建一个空文本文件,然后转到命令提示符,将文件名更改为.gitignore:
ren "New Text Document.txt" .gitignore
现在用您最喜欢的文本编辑器打开文件,并添加您希望忽略的文件/文件夹名称。也可以使用通配符,如*.txt。
在Windows和Mac上,如果要忽略当前目录中名为Flower_Data_folder的文件夹,可以执行以下操作:
echo Flower_Data_Folder >> .gitignore
如果是名为data.txt的文件:
echo data.txt >> .gitignore
如果是类似“Data/passwords.txt”的路径
echo "Data/passwords.txt" >> .gitignore.
如果您想维护一个文件夹而不是其中的文件,只需在文件夹中放置一个“.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
在Unix上:
touch .gitignore
在Windows上:
echo > .gitignore
在终端中执行的这些命令将在当前位置创建.gitignore文件。
然后只需将信息添加到此.gitignore文件(例如使用Notepad++),哪些文件或文件夹应被忽略。保存更改。就是这样:)
更多信息:.gitignore
我认为问题是你的工作树是这样的:
a-cache/foo
a-cache/index.html
b-cache/bar
b-cache/foo
b-cache/index.html
.gitignore
…用你描述的.gitignore。这将为您提供git状态输出,如:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# a-cache/
# b-cache/
…如果index.html文件尚未添加到存储库中。(Git发现缓存目录中有未忽略的文件,但它只报告目录。)要解决此问题,请确保您已添加并提交了index.html文件:
git add *cache/index.html
git commit -m "Adding index.html files to the cache directories"
…然后您的git状态将如下所示:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)
(很明显,你也希望提交.gitignore。我只是懒得处理这个测试用例。)
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 我如何找到哪个程序正在使用端口80在Windows?
- 在Windows中有像GREP这样的模式匹配实用程序吗?
- 试图在Windows 10上运行Python时出现“权限被拒绝”
- 如何在Windows命令提示符下运行.sh ?
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖