2011-10-07 93 views
6

我有一個測試模塊,它將刪除並重新創建git目錄子目錄中的.apk文件。.gitignore和git rm --cached不會讓文件不被跟蹤

我已經添加了這些來的.gitignore(目錄,明確的文件和* .apk文件),然後我做了

git rm -r --cached src/main/Tests/bin 

和git告訴我:

rm 'src/main/Tests/bin/Tests-debug-unaligned.apk' 
rm 'src/main/Tests/bin/Tests-debug.apk' 
rm 'src/main/Tests/bin/Tests.ap_' 
rm 'src/main/Tests/bin/classes.dex' 

然後我

git commit . -m "removed apk files" 

我再次運行測試,刪除文件並重新創建它們。我運行git狀態,並顯示爲已修改。看來.gitignore不起作用。這裏是我的.gitignore文件

*ipr 
*iml 
*iws 
.gitignore 
out/ 
*apk 
src/main/Tests/bin 
src/main/Tests/bin/* 
src/main/Tests/bin/Tests-debug-unaligned.apk 
+0

是因爲你還沒有加入到他們已經取下後他們的.gitignore? –

回答

1

我剛試過你的食譜,它對我有用。

~ % mkdir deleteme 
~ % cd deleteme 
~/deleteme % mkdir src src/main src/main/Tests src/main/Tests/bin 
~/deleteme % touch src/main/Tests/bin/blah.apk     
~/deleteme % git init 
Initialized empty Git repository in /Users/sri/deleteme/.git/ 
~/deleteme (master*) % touch src/main/hello.txt 
~/deleteme (master*) % git add . 
~/deleteme (master*) % git commit -m "init" 
[master (root-commit) 0ef5764] init 
0 files changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 src/main/Tests/bin/blah.apk 
create mode 100644 src/main/hello.txt 
~/deleteme (master) % vi .gitignore 
~/deleteme (master) % git rm -r --cached src/main/Tests/bin 
rm 'src/main/Tests/bin/blah.apk' 
~/deleteme (master*) % git commit -m "removed" 
[master 5ca6456] removed 
0 files changed, 0 insertions(+), 0 deletions(-) 
delete mode 100644 src/main/Tests/bin/blah.apk 
~/deleteme (master) % touch src/main/Tests/bin/blah.apk  
~/deleteme (master) % git status 
# On branch master 
nothing to commit (working directory clean) 
~/deleteme (master) % 

也許在壓倒一切的你已經在你gitconfig都表示什麼其他目錄(或全局指令)的gitconfig。你沒有提到,這個gitconfig位於。請參閱gitignore手冊頁或聯機幫助文檔,瞭解可以指定忽略規則的各個位置的優先順序。該名男子頁說...

... 優先順序如下,從最高到最低(優先級一個級別內,在最近匹配 格局決定結局): 模式從命令讀取這些命令支持 這些命令。

o Patterns read from a .gitignore file in the same directory as the path, or in any 
     parent directory, with patterns in the higher level files (up to the toplevel of the 
     work tree) being overridden by those in lower level files down to the directory 
     containing the file. These patterns match relative to the location of the .gitignore 
     file. A project normally includes such .gitignore files in its repository, containing 
     patterns for files generated as part of the project build. 

    o Patterns read from $GIT_DIR/info/exclude. 

    o Patterns read from the file specified by the configuration variable core.excludesfile 
0

你嘗試過

*.apk 
在你的.gitignore

?如果他們之前被跟蹤過,則需要刪除它們並在設置.gitignore之前進行確認。一旦它們出來,添加在.gitignore文件中的條目,它應該工作。

+0

我承諾刪除這些文件。我知道它然後「應該工作」,但事實並非如此。 – browep

+0

* apk以及它們所在的目錄以及一個絕對路徑,僅用於良好測量,結果相同 – browep

+2

清除.gitignore文件以使其沒有任何.apk條目。承諾。刪除apk文件。 git add -A並提交。只需將* .apk添加到忽略文件即可。承諾。你現在應該正確地忽略這些文件。你可以通過執行git reset來將所有這些清理工作壓縮到一個提交中--soft head〜3 && git add -A && git commit -m「fixed ignore」 –

27

我認爲你需要使用清潔你的所有stagged文件:

git rm -r --cached . 

git add -A 

然後提交:

git commit -m ".gitignore" 

但要確保你在此之前提交更改。

相關問題