是否可以将.gitignore
文件添加到.gitignore
自身?
.gitignore
Run Code Online (Sandbox Code Playgroud)
虽然不起作用
我不想在编辑过的文件中看到它
Lar*_*röm 139
该.gitignore
文件旨在防止在项目上进行协作的每个人在项目中包含一些常见文件,例如生成的缓存文件.因此你不应该忽视.gitignore
,因为它的目的是被包含在回购中.
如果您只想忽略一个仓库中的文件但没有提交忽略列表,则可以将它们添加到.git/info/exclude
该仓库中.
如果要忽略计算机上每个存储库上的某些文件,可以创建该文件~/.gitignore_global
然后运行
git config --global core.excludesfile ~/.gitignore_global
Run Code Online (Sandbox Code Playgroud)
Mar*_*ase 29
如果从未检入过, .gitignore可以忽略它自己:
mhaase@ubuntu:~$ git --version
git version 1.7.9.5
mhaase@ubuntu:~$ git init temp
Initialized empty Git repository in /home/mhaase/temp/.git/
mhaase@ubuntu:~$ cd temp
mhaase@ubuntu:~/temp$ touch .gitignore foo bar baz bat
mhaase@ubuntu:~/temp$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# bar
# bat
# baz
# foo
mhaase@ubuntu:~/temp$ echo "foo" >> .gitignore
mhaase@ubuntu:~/temp$ echo ".gitignore" >> .gitignore
mhaase@ubuntu:~/temp$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# bar
# bat
# baz
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
如果您签入.gitignore(在您告诉它忽略自己之前),那么它将始终以git状态显示,即使您稍后修改它以忽略它自己.
Arn*_*yal 12
输入.gitignore
gitignore 文件后,请尝试以下操作,
git rm -r --cached .
git add --all
git commit -m "ignoring gitignore"
git push --set-upstream origin master
Run Code Online (Sandbox Code Playgroud)
它应该可以工作,尽管就像已经说过的那样,如果您的存储库由多个用户共享,则忽略 gitignore 可能会适得其反。
归档时间: |
|
查看次数: |
49405 次 |
最近记录: |