2016-07-29 376 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'说不同。 –