Description :
當在git project 底下,若有些檔案無法加入(git add),很有可能是被 git ignore了。
詳細說明參考這篇(http://stackoverflow.com/questions/1084969/unable-to-track-files-within-git-submodules)
以下節錄相關的說明
大部分的情況下,檔案被 git ignore,有2個主要原因:.gitignore 和 submodule。
.gitignore 是一個說明檔和 .git 位於同一層,主要的用途就是忽略不需要追蹤的檔案。
以 android project 為例,當進行clean 和build 的動作都會讓bin/ 資料夾內的檔案重新生成。
這些重新生成的檔案多半是不需要追蹤,因此就能藉由 .gitignore 說明檔來描述哪些檔案不需要追蹤。
以下為簡單的範例
這是剛建立完成android project並初始化 git(git init)的情況。可以看到 bin/ 資料夾。
# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .classpath # .project # AndroidManifest.xml # bin/ # gen/ # ic_launcher-web.png # libs/ # proguard-project.txt # project.properties # res/ # src/
接著建立 .gitignore 檔案。
vim .gitignore 並填入 bin/ (bin/ 的意思為忽略 bin/ 內所有檔案)
再輸入 git status 觀察,可以看到多了.gitignore ,少了bin/
# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .classpath # .gitignore # .project # AndroidManifest.xml # gen/ # ic_launcher-web.png # libs/ # proguard-project.txt # project.properties # res/ # src/
此即為第一種 git ignore 的情況,若直接輸入 git add bin/ , git 會說明情況
The following paths are ignored by one of your .gitignore files: bin Use -f if you really want to add them. fatal: no files added
強制加入請輸入 git add –force bin/
# On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: bin/AndroidManifest.xml # new file: bin/R.txt # new file: bin/classes/android/support/v7/appcompat/R$anim.class # new file: bin/classes/android/support/v7/appcompat/R$attr.class # new file: bin/classes/android/support/v7/appcompat/R$bool.class # new file: bin/classes/android/support/v7/appcompat/R$color.class # new file: bin/classes/android/support/v7/appcompat/R$dimen.class # new file: bin/classes/android/support/v7/appcompat/R$drawable.class # new file: bin/classes/android/support/v7/appcompat/R$id.class ...
第2種情況為 submodule。
這種情況比較複雜一些,必須進行4個步驟。
Note : 注意這4個步驟可能會毀損 git repo,若不確定情況,可以先試試第3步驟。
1. 在.gitmodule中刪除相關的連結
2. 在.git/config中刪除相關的連結
3. 執行 git rm –cached path_to_submodule
rm 'path_to_submodule'
4. 執行 git commit
a[master 5c270a9] [xxxx] Remove file in submodule. 1 file changed, 1 deletion(-) delete mode 160000 path_to_submodule