我們有一個深層次的目錄結構,其中包含多個不同級別的README文件。例如:Git add。在具有.git文件夾的子目錄上失敗,即使被忽略
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
文件。我們成功地測試此與this.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
文件夾「untracking」子目錄中的問題,我提出一個完全新鮮的創作git倉庫的。注意:作爲遠程添加的存儲庫是新近鑄造的--bare
存儲庫。
[email protected]:/home/.../TopLevel$ rmdir .git
[email protected]:/home/.../TopLevel$ git init
Initialized empty Git repository in /home/.../TopLevel/.git/
[email protected]:/home/.../TopLevel$ git remote add origin [email protected]:path/repo.git
[email protected]:/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)
[email protected]:/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 .'嗎?後者僅用於第一次提交,對吧? – mickdev
那麼,這是第一次提交:)但我只是嘗試'git add --all'並得到了相同的錯誤:( – abalter
我看到了......你是否嘗試使用'rm -fr .git'刪除所有配置的git?然後'git init'然後'git add .'? – mickdev