Git Ignores and Maven targets

后端 未结 5 1873
予麋鹿
予麋鹿 2020-11-30 17:35

Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git.

I\'m looking to exclude all the \'target\' f

相关标签:
5条回答
  • 2020-11-30 18:03

    I ignore all classes residing in target folder from git. add following line in open .gitignore file:

    /.class

    OR

    */target/**

    It is working perfectly for me. try it.

    0 讨论(0)
  • 2020-11-30 18:10

    add following lines in gitignore, from all undesirable files

    /target/
    */target/**
    **/META-INF/
    !.mvn/wrapper/maven-wrapper.jar
    
    ### STS ###
    .apt_generated
    .classpath
    .factorypath
    .project
    .settings
    .springBeans
    .sts4-cache
    
    ### IntelliJ IDEA ###
    .idea
    *.iws
    *.iml
    *.ipr
    
    ### NetBeans ###
    /nbproject/private/
    /build/
    /nbbuild/
    /dist/
    /nbdist/
    /.nb-gradle/
    
    0 讨论(0)
  • 2020-11-30 18:17

    It is possible to use patterns in a .gitignore file. See the gitignore man page. The pattern */target/* should ignore any directory named target and anything under it. Or you may try */target/** to ignore everything under target.

    0 讨论(0)
  • 2020-11-30 18:26

    The .gitignore file in the root directory does apply to all subdirectories. Mine looks like this:

    .classpath
    .project
    .settings/
    target/
    

    This is in a multi-module maven project. All the submodules are imported as individual eclipse projects using m2eclipse. I have no further .gitignore files. Indeed, if you look in the gitignore man page:

    Patterns read from a .gitignore file in the same directory as the path, or in any parent directory

    So this should work for you.

    0 讨论(0)
  • 2020-11-30 18:26

    As already pointed out in comments by Abhijeet you can just add line like:

    /target/**
    

    to exclude file in \.git\info\ folder.

    Then if you want to get rid of that target folder in your remote repo you will need to first manually delete this folder from your local repository, commit and then push it. Thats because git will show you content of a target folder as modified at first.

    0 讨论(0)
提交回复
热议问题