2016-07-29 382 views
2

我希望我的.gitignore忽略某些文件夾和文件,所以我想出了以下內容:的Git忽略不忽略指定的文件夾/文件

*.class 

# usual java ignores 
bin/ 
.metadata 

# Maven 
*/target/* 
target/* 
/target/ 
*/deploy/* 
deploy/* 

# src-gen folder is populated by the command of protobuf, these files should not be pushed 
src-gen/* 

# eclipse generated stuff 
dependency-reduced-pom.xml 

# we shouldn't have .jar files in our repository, 
# apart from these 5 jars which are vital for our build process 
*.jar 
!/projectName/bundle/**/*.jar 

# For Unix editors 
# sometimes make file copies ending 
# with ~ 
# To ignore them use: 
*~ 

# For Mac 
.DS_Store 
._* 

# For markdown read me files 
.README.md.html 

然而,git status後,我看不到任何東西作爲輸出被刪除。請注意,這是一個子模塊,如果這很重要的話。我希望這個.gitignore在不指定任何文件夾名稱的情況下忽略所有內容,因爲我不需要任何硬編碼。

這裏的文件夾結構,我有:

+ parentRepo 
    + thisRepo 
    + .gitignore 
    + projectName 
     + src-gen 
     + target 
     + deploy 
     + dependency-reduced-pom.xml 
     + bundle 
     + system 
      + 1.jar 
      + 2.jar 
      + 3.jar 
      + 4.jar 
      + 5.jar 

回答

3

「我看不到任何要刪除的東西」 - 您剛剛告訴git忽略某些文件;現在你期望它刪除它們?

.gitignore僅用於尚未被追蹤的文件(即新文件添加到存儲庫時)。如果文件已存在於存儲庫中,並且您希望git忽略它,則必須將其從存儲庫中移除(git rm --cached file)並提交更改。

0

確保您.gitignore是在根目錄下。在該目錄中運行git status,並將狀態輸出中的路徑複製到文件中,並將其粘貼到.gitignore中。

.gitignore只會忽略您尚未添加到存儲庫的文件。

+0

因此,我將只有1.gitignore(在父目錄中),它也會爲子模塊做所有事情? –

+0

是的,但要確保你想忽略的文件,你沒有將文件添加到git倉庫。 – Aakash

+0

[一些](http://stackoverflow.com/a/5127213/6533075)對所有的'.gitignore'說不同。 –