是否可以将.gitignore文件添加到.gitignore本身?
.gitignore
但这并不奏效
我不想在编辑过的文件里看到它
是否可以将.gitignore文件添加到.gitignore本身?
.gitignore
但这并不奏效
我不想在编辑过的文件里看到它
是的,你可以;您仍然可以在编辑过的文件中看到它,因为它仍然被git跟踪,并且被git跟踪的文件总是被标记为已修改,即使它们位于.gitignore中。所以不要追踪它。
但是为什么不提交或重置您在上面所做的更改呢?这是一个更好的方法来删除它的地位…还要注意,任何新的repo副本都必须添加它的.gitignore,这可能很烦人。
gitignore文件的目的是防止在项目中协作的每个人意外地提交项目中的一些常见文件,例如生成的缓存文件。因此,您不应该忽略.gitignore,因为它应该包含在存储库中。
如果你只想忽略一个存储库中的文件,但又不想提交忽略列表(例如个人文件),你可以将它们添加到该存储库中的.git/info/exclude中。
如果您想忽略机器上每个存储库中的某些文件,可以创建文件~/。Gitignore_global然后运行
git config --global core.excludesfile ~/.gitignore_global
如果.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)
如果签入.gitignore(在告诉它忽略自身之前),那么它将始终显示在git状态中,即使稍后修改它以忽略自身。
在您的gitignore文件中输入.gitignore后,尝试以下操作,
git rm -r --cached .
git add --all
git commit -m "ignoring gitignore"
git push --set-upstream origin master
它应该工作,尽管如前所述,忽略gitignore可能适得其反,如果你的回购是由多个用户共享。