Git不跟踪文件夹

时间:2018-09-22 06:11:28

标签: git github gitignore

我正在尝试使用git跟踪我的dotfile和配置文件夹。 我将.gitignore设置为忽略所有(*),但忽略要跟踪的文件和文件夹:

### Gitignore
# ignore all
**
!**/
# but...
# files
!.vimrc
!.Xdefault
!.bashrc
!.profile
!.xsession
!.gitignore
# folders
!.vim/**
!.config/i3/**
!.config/ranger/**

这仅适用于文件,不适用于文件夹。 如果我尝试手动添加文件夹(例如git add .config/i3),则会得到The following paths are ignored by one of your .gitignore files: .config/i3 Use -f if you really want to add them

1 个答案:

答案 0 :(得分:0)

如果您忽略所有内容:**,则需要在之前将文件夹列入白名单,以便能够排除文件(因为如果忽略了文件夹,则其内容将被赢得)不会被排除在外)

所以:

**
!**/

然后,您可以添加文件排除项:

# but 
# files (eg)
!.Xdefaults
!.vimrc
# etc
# folders (eg)
!./.vim/**
!./.config/ranger/**
!./.config/i3/**

使用git check-ignore -v -- a/file确认这些规则确实适用。