我们有一个深度目录结构,其中包含不同级别的多个 README 文件。例如:
gitignoretest/
|-- 00README
|-- dir1
| |-- 00README
| |-- dir1
| | |-- 00README
| | |-- dir1
| | |-- dir2
| | |-- dir3
| | |-- file1
| | `-- file2
| |-- dir2
| | |-- 00README
| | |-- dir1
| | |-- dir2
| | |-- dir3
| | |-- file1
| | `-- file2
| |-- dir3
| | |-- 00README
| | |-- dir1
| | |-- dir2
| | |-- dir3
| | |-- file1
| | `-- file2
| |-- file1
| `-- file2
|-- dir3
| |-- 00README
| |-- dir1
| | |-- 00README
| | |-- dir1
| | | |-- 00README
| | | |-- dir1
| | | |-- dir2
| | | |-- dir3
| | | |-- file1
| | | `-- file2
| | |-- dir2
| | | |-- 00README
| | | |-- dir1
| | | |-- dir2
| | | |-- dir3
| | | |-- file1
| | | `-- file2
...
...
我们只想对00README
文件进行版本控制。我们用这个成功地测试了这个 .gitignore
.gitignore
# Ignore everything
*
# But not these files...
!.gitignore
!00README
# etc...
# ...even if they are in subdirectories
!*/
然而,在实际场景中,其中一个子目录是一个conda
安装,其中包含一些包含它们自己的.git
目录的包。当我这样做git add .
时,它会失败并显示以下消息:
fatal: Not a git repository: Applications/conda/lib/STAR-Fusion/STAR-Fusion.wiki/../.git/modules/STAR-Fusion.wiki
真实情况../TopLevel/Applications/...
是../TopLevel/.gitignore
. 以下是我尝试过的事情:
../TopLevel/.gitignore
# Ignore everything
*
/Applications/conda/**/*
/Applications/miniconda3/**/*
/Applications/newconda/**/*
Applications/conda/**/*
Applications/miniconda3/**/*
Applications/newconda/**/*
/**/.git
**/.git
/**/.git/**
**/.git/**
# But not these files...
!.gitignore
!00README.md
!USE_APPS
# etc...
# ...even if they are in subdirectories
!*/
但没有达到目标。
编辑
为了解决@VonC.git
提到的带有文件夹的“取消跟踪”子目录的问题,我提出了一个全新的 git 存储库创建。注意:作为远程添加的存储库是新创建的--bare
存储库。
balter@server:/home/.../TopLevel$ rmdir .git
balter@server:/home/.../TopLevel$ git init
Initialized empty Git repository in /home/.../TopLevel/.git/
balter@server:/home/.../TopLevel$ git remote add origin git@server.ohsu.edu:path/repo.git
balter@server:/home/.../TopLevel$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# 00README.md
# Applications/
# InstallationPackages/
# USE_APPS
# gitignoretest/
nothing added to commit but untracked files present (use "git add" to track)
balter@server:/home/.../TopLevel$ git add .
fatal: Not a git repository: Applications/conda/lib/STAR-Fusion/STAR-Fusion.wiki/../.git/modules/STAR-Fusion.wiki