我想创建一个我的bash设置和插件以及诸如此类的git repo。我忽略了所有内容(第0行),然后在repo中手动添加了我想要的文件/文件夹。 (我必须这样做,因为repo在我的~
文件夹中。)我想忽略.vim / colors /目录中的所有颜色配置文件,但我确实想要包含我的一个文件使用(apprentice.vim)。
.vim/colors/*
行似乎不起作用 - 它根本不会忽略任何文件。使用!!.vim/colors/*
也无效。我怎么能让它覆盖所有以前的规则并忽略colors文件夹,然后仍然允许忽略apprentice.vim文件?
/*
*.swp
!.gitignore
!.bashrc
!.bash_profile
!.vimrc
!.vim
.vim/colors/* # Don't include all of the other color schemes
!.vim/colors/apprentice.vim
答案 0 :(得分:5)
问题是与# comment
位于同一行的.vim/colors/*
,但这里有另一种选择。
gitignore的主要规则是:
It is not possible to re-include a file if a parent directory of that file is excluded.
这意味着:
(假设元素尚未版本化,在这种情况下,您需要首先git rm --cached
:
**
'**/
”结果:
/**
!/**/
!exclude what you want to *not* be ignored
# for instance
.vim/colors/* # Don't include all of the other color schemes
!.vim/colors/apprentice.vim
使用git check-ignore -v
检查什么是和不被忽略(-v
很重要):
git check-ignore -v -- afile
比手动取消忽略子文件夹更容易,尤其是当要忽略的子文件夹内容有几个级别时:要排除a/b/c
中的文件,首先需要忽略!/a
,然后!/a/b
,然后是!/a/b/c
)
插图/测试:
C:\Users\vonc\prog\git\tests>git init i
Initialized empty Git repository in C:/Users/vonc/prog/git/tests/i/.git/
C:\Users\vonc\prog\git\tests>cd i
C:\Users\vonc\prog\git\tests\i>mkdir .vim\colors
C:\Users\vonc\prog\git\tests\i>touch .vim\colors\apprentice.vim
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
.vim/
nothing added to commit but untracked files present (use "git add" to track)
简单.gitignore
/*
规则:
C:\Users\vonc\prog\git\tests\i>sbt .gitignore
/*
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
让我们添加!.gitignore
现在可以跟踪.gitignore
。
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
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)
但如果我补充:
.vim/colors/*
!.vim/colors/apprentice.vim
.vim
所有内容仍然被忽略:
C:\Users\vonc\prog\git\tests\i>git st
On branch master
Initial commit
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)
让我们用git check-ignore
:
C:\Users\vonc\prog\git\tests\i>git check-ignore -v -- .vim\colors\apprentice.vim
.gitignore:1:/* ".vim\\colors\\apprentice.vim"
添加!.vim
有效,因为它取消忽略该文件夹,允许该文件夹中的其他规则应用。
但是,这更简单:
/**
!/**/
!.gitignore
.vim/colors/*
!.vim/colors/apprentice.vim
答案 1 :(得分:2)
你的规则似乎没问题。除*.swp
以外,/*
将涵盖git rm --cached ./.vim/colors/*
git add ./.vim/colors/
git commit -m"Unstaged .vim/colors"
以及评论不属于自己的行。
如果您的文件已经暂存,您可能需要取消暂存它们并将其从存储库中删除,然后再读取它们。
/*
!.gitignore
!.bashrc
!.bash_profile
!.vimrc
!.vim
.vim/colors/*
!.vim/colors/apprentice.vim
最终.gitignore使用
class Players(models.Model):
name = models.CharField(max_length=25) # nazwa gracza
class Game(models.Model):
name = models.CharField(max_length=25) # nazwa gry
turn = models.IntegerField(default=1) # numer gracza ktory aktualnie rzuca
rabbit = models.IntegerField(default=60)
sheep = models.IntegerField(default=24)
pig = models.IntegerField(default=20)
cow = models.IntegerField(default=12)
horse = models.IntegerField(default=6)
small_dog = models.IntegerField(default=4)
big_dog = models.IntegerField(default=2)
class GamePlayer(models.Model):
game = models.ForeignKey(Game, on_delete=models.CASCADE)
player = models.ForeignKey(Players, on_delete=models.CASCADE)
turn = models.IntegerField()
rabbit = models.IntegerField(default=0)
sheep = models.IntegerField(default=0)
pig = models.IntegerField(default=0)
cow = models.IntegerField(default=0)
horse = models.IntegerField(default=0)
small_dog = models.IntegerField(default=0)
big_dog = models.IntegerField(default=0)