我们有一个深层次的目录结构,不同层级上有多个README文档。例如:
我们希望仅对
实际情况是
../TopLevel/.gitignore
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
!*/
然而,在实际情况下,其中一个子目录是一个包含其自己的.git
目录的conda
安装。当我执行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
git add --all
而不是git add .
吗?后者只适用于第一次提交,对吧? - mickdevgit add --all
,仍然得到了相同的错误 :( - abalterrmdir .git; git init; git remote add origin git@......git; git add .
仍然出现相同的错误 :( - abalterconda update
时,它都会回来,而且可能有很多包都有这个问题 :( - abalter