2017-03-07 100 views
3

我們有一個深層次的目錄結構,其中包含多個不同級別的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 
+0

你嘗試過'git add --all'而不是'git add .'嗎?後者僅用於第一次提交,對吧? – mickdev

+0

那麼,這是第一次提交:)但我只是嘗試'git add --all'並得到了相同的錯誤:( – abalter

+0

我看到了......你是否嘗試使用'rm -fr .git'刪除所有配置的git?然後'git init'然後'git add .'? – mickdev

回答

1

如果你要考慮所有的樹結構作爲一個信息庫,您需要先刪除嵌套.git子文件夾:詳見「Initial push to GitHub Missing Sub Directory」。

對於無視規則,如果你想不顧一切,但OOREMEADE文件,你需要最前一頁排除的文件夾

* 
!**/ 

然後你就可以排除文件:

!00README 

確保那些文件首先未被跟蹤(git status

我們的應用程序目錄有一個con da安裝,似乎通過克隆git存儲庫來安裝許多軟件包。如果我去刪除所有的.git目錄,那麼每當我運行conda更新時,它會失敗,因爲它不再需要它的回購,或者它會重新克隆它們。

首先,你不要忽略.git文件夾:他們的父文件夾代表一個嵌套的git倉庫。這是您要忽略文件夾(.git文件夾的父),這樣一git add .不會記錄gitlinkspecial entry in index of the parent repo

其次,「Not a git repository: .../../.git/modules/...」是指暢達嵌套式回購具有submodules ,其support is still in progress with conda:該conda安裝文件夾將需要git submodule update --init --recursive爲了初始化正確的嵌套子模塊。

+0

嘗試它。幾個問題:1)它在我們的測試目錄中「工作」,儘管沒有文件夾2)如果我理解,'!** /'是忽略任何實際上是文件夾而不是文件的東西。 T' – abalter

+0

@abalter 2)是:如果文件夾被忽略,涉及該被忽略的子文件夾中的元素的任何規則根本不會被使用。 1)什麼是問題;) – VonC

+0

試過以上,並仍然有致命的錯誤:(關於1)的問題是,在測試目錄(原始問題中顯示的樹),我顯示'.gitignore'工作正常忽略目錄。那麼爲什麼當某個地方有一個'.git'目錄時會失敗呢?也許我需要忽略所有以「。」開頭的目錄? – abalter