我在版本控制下有我的Git bash主目录。我正在使用白名单(忽略所有除了...... ):
$ cat .gitignore
# Ignore all the things
*
# But not these (with exceptions)
!*.bash_aliases
!*.bash_profile
!*.bashrc
!*.drush/
!*.drush/*
.drush/cache
!.gitconfig
!.gitignore
!.gitalias
!*.minttyrc
!*.vim/
!*.vim/*
.vim/.netrwhist
!*.vimrc
我想将.ssh/config
添加到异常中,但我似乎没有得到正确的语法。
$ ls .ssh/config
.ssh/config
我在.gitignore
:
$ git diff
diff --git a/.gitignore b/.gitignore
index 22b3a79..b84bcd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
!.gitignore
!.gitalias
!*.minttyrc
+!.ssh/config
!*.vim/
!*.vim/*
.vim/.netrwhist
然而,它并没有被忽视:
~ (master)
$ git status
Changes not staged for commit:
modified: .gitignore
no changes added to commit (use "git add" and/or "git commit -a")
查看.gitignore中其他内容的语法,我尝试了这个:
$ git diff
diff --git a/.gitignore b/.gitignore
index 22b3a79..659d7be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
!.gitignore
!.gitalias
!*.minttyrc
+!*.ssh/config
!*.vim/
!*.vim/*
.vim/.netrwhist
无济于事:
$ git status
Changes not staged for commit:
modified: .gitignore
no changes added to commit (use "git add" and/or "git commit -a")
在.ssh/config
中添加.gitignore
作为例外的语法是什么?
答案 0 :(得分:1)
git help ignore
:
如果排除该文件的父目录,则无法重新包含文件。
所以尝试添加:
!.ssh/
答案 1 :(得分:0)
关于jingx的答案,我添加了这些内容:
!*.ssh/
!*.ssh/config
它似乎有效:
$ git add .gitignore
$ git status
Changes to be committed:
modified: .gitignore
new file: .ssh/config
$ git add .ssh/known_hosts
The following paths are ignored by one of your .gitignore files:
.ssh/known_hosts
Use -f if you really want to add them.