ste*_*tew 1458
创建.gitignore
项目目录中指定的文件.通过在文件中输入目录名来忽略目录(附加斜杠):
dir_to_ignore/
Run Code Online (Sandbox Code Playgroud)
更多信息在这里.
小智 196
默认情况下,Windows资源管理器将.gitignore
在实际上显示文件名时显示.gitignore.txt
Git不会用 .gitignore.txt
并且您无法将文件重命名为,.gitignore
因为资源管理器认为它是一个没有名称的gitignore类型的文件.
非命令行解决方案:
You can rename a file to ".gitignore.", and it will create ".gitignore"
Vai*_*ris 98
似乎忽略文件和目录有两种主要方式:
的.gitignore
.gitignore
文件放入repo的根目录旁边.git
(在Windows中,确保您看到真正的文件扩展名然后make .gitignore.
(使用最后的点来建立空文件扩展名))~/.gitignore_global
并运行git config --global core.excludesfile ~/.gitignore_global
以将其添加到您的git配置中注意:以前跟踪的文件可以通过运行来解除跟踪 git rm --cached filename
回购排除 - 对于不需要共享的本地文件,只需将文件模式或目录添加到文件中即可.git/info/exclude
.这些规则没有提交,所以其他用户在这里看不到更多信息
[已更新]要在忽略的文件列表中生成例外,请参阅此问题.
sf.*_*sf. 43
我在Windows资源管理器中使用a创建文件时遇到了一些问题.在开始.
一个解决方法是进入命令空间并使用"编辑"创建一个新文件
Mah*_*hes 41
要指示GIT忽略某些文件或文件夹,您必须创建.gitignore
文件.
但在Windows资源管理器中你必须提供文件的名称,你只是无法创建只有扩展名的文件,诀窍是创建一个空文本文件并转到命令提示符并将文件名更改为 .gitignore
ren "New Text Document.txt" .gitignore
Run Code Online (Sandbox Code Playgroud)
现在用您喜欢的文本编辑器打开文件,并添加您希望忽略的文件/文件夹名称.你也可以使用这样的通配符*.txt
希望它能回答你的问题
sen*_*rio 19
如果要维护文件夹而不是文件夹中的文件,只需将".gitignore"文件放在文件夹中,并以"*"作为内容.此文件将忽略存储库中的所有内容.但是.gitignore
会包含在你的回购中.
$ git add path/to/folder/.gitignore
Run Code Online (Sandbox Code Playgroud)
如果添加空文件夹,则会收到此消息(.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
Run Code Online (Sandbox Code Playgroud)
所以,使用"-f"强制添加:
$ git add path/to/folder/.gitignore -f
Run Code Online (Sandbox Code Playgroud)
wor*_*art 16
在Windows中,有一个额外的斜杠.剔除在一个目录中的.gitignore与
dir_to_exclude /
可能会工作,但排除所有目录
/
当你的目录中有空格(如my file.txt
)的文件名时会导致问题:Git bash用反斜杠(比如my\ file.txt
)转义这些空格,而Git for Windows不区分/
和\
.
要排除所有目录,最好使用:
**/
两个连续的星号表示目录内容.
Eat*_*oes 12
如果您需要排除子文件夹,可以使用**
通配符排除任何级别的子目录.
**/build/output/Debug/
Run Code Online (Sandbox Code Playgroud)
J-D*_*zle 11
要忽略git中的整个目录,最简单的方法是在目标目录中包含一个.gitignore文件,该文件只包含"*"
一个例子,
示例系统
/root/
.gitignore
/dirA/
someFile1.txt
someFile2.txt
/dirB/
.gitignore
someFile3.txt
someFile4.txt
Run Code Online (Sandbox Code Playgroud)
目标
顶级.gitignore(/root/.gitignore)
忽略目录.gitignore(/root/dirB.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/
Run Code Online (Sandbox Code Playgroud)
我将文件夹"assets"和"compiled"添加到要忽略的文件和目录列表中.
我在使用git来获取Windows上的.gitignore文件时遇到了一些问题.$ GIT_DIR/info/exclude文件似乎总是有效.但是,这种方法的缺点是$ GIT_DIR目录中的文件不包含在签入中,因此不共享.
(ps $ GIT_DIR通常是名为.git的隐藏文件夹)
您可以使用以下内容创建".gitignore"文件:
*
!.gitignore
Run Code Online (Sandbox Code Playgroud)
它适用于我和简单.
在 Windows 和 Mac 上,如果要忽略当前目录中名为 Flower_Data_Folder 的文件夹,可以执行以下操作:
echo Flower_Data_Folder >> .gitignore
Run Code Online (Sandbox Code Playgroud)
如果它是一个名为的文件data.txt
:
echo data.txt >> .gitignore
Run Code Online (Sandbox Code Playgroud)
如果是“Data/passwords.txt”这样的路径
echo "Data/passwords.txt" >> .gitignore.
Run Code Online (Sandbox Code Playgroud)
我假设问题是你的工作树是这样的:
a-cache/foo
a-cache/index.html
b-cache/bar
b-cache/foo
b-cache/index.html
.gitignore
Run Code Online (Sandbox Code Playgroud)
......跟.gitignore
你描述的一样.这将为您提供如下git status
输出:
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# a-cache/
# b-cache/
Run Code Online (Sandbox Code Playgroud)
... 如果该index.html
文件还没有被添加到库中.(git看到缓存目录中有未签名的文件,但只报告目录.)要解决此问题,请确保已添加并提交了index.html
文件:
git add *cache/index.html
git commit -m "Adding index.html files to the cache directories"
Run Code Online (Sandbox Code Playgroud)
......然后你的git status
意志如下:
$ 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)
Run Code Online (Sandbox Code Playgroud)
(显然你也想提交.gitignore
,我只是对这个测试用例很懒.)
小智 5
在Unix上:
touch .gitignore
Run Code Online (Sandbox Code Playgroud)
在Windows上:
echo > .gitignore
Run Code Online (Sandbox Code Playgroud)
在终端中执行的这些命令将.gitignore
在当前位置创建一个文件。
然后只需向该.gitignore
文件添加信息(例如,使用Notepad ++),即可忽略哪些文件或文件夹。保存您的更改。而已 :)
详细信息:.gitignore