Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ignore directories "build" and all their contents but not "build.xml"

Tags:

git

gitignore

ant

I am using git in a project where Ant is the build system. Since I do not wish to add "build" directories to git but need to add build.xml files I have resorted to the following two lines in my .gitignore files:

build/
!build.xml

Is there a better / more concise way ?

UPDATE: turns out build.xml was ignored due to a .gitignore in a directory higher up the path. Once that was removed, build/ correctly ignores only the build folder, not the build.xml file beside it.

like image 729
Marcus Junius Brutus Avatar asked Nov 12 '12 09:11

Marcus Junius Brutus


People also ask

How do I set Git to ignore all text files?

You can create a . gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the . gitignore file in to your repository.

Why Git ignore is not ignoring files?

Git can only ignore files that are untracked - files that haven't been committed to the repository, yet. That's why, when you create a new repository, you should also create a . gitignore file with all the file patterns you want to ignore.

Does Git build/ ignore the build folder?

Once that was removed, build/ correctly ignores only the build folder, not the build.xml file beside it. I just want git to ignore the build folder but include under version control the build.xml file that sits alongside it (not inside it).

How to ignore all other files in the build folder?

To be precise, As you want to have the folder and ignore all other files in it except build.xml. Note though that common directory layout for Ant is that build.xml is in the app root folder, whereas build folder only contains files created during build. See further rationale in, for example, here. in .gitignore should be enough.

Why is my build XML file being ignored?

UPDATE: turns out build.xml was ignored due to a .gitignore in a directory higher up the path. Once that was removed, build/ correctly ignores only the build folder, not the build.xml file beside it.

What is the difference between build and build folder in ant?

Note though that common directory layout for Ant is that build.xml is in the app root folder, whereas build folder only contains files created during build. See further rationale in, for example, here.


2 Answers

No, there is no better way, that's pretty much the way to do it. To be precise,

build/*
!build/build.xml

As you want to have the folder and ignore all other files in it except build.xml.

Note though that common directory layout for Ant is that build.xml is in the app root folder, whereas build folder only contains files created during build. See further rationale in, for example, here.


Edit. if you actually have build.xml in the app root, just

build

in .gitignore should be enough. However, it should be noted it only applies to detecting new entries, if you've already committed something to git, you'll have to remove that yourself.

like image 75
eis Avatar answered Oct 21 '22 01:10

eis


You can also just ignore /build/, that will ignore only the folder called build, no files.

like image 41
Nick Avatar answered Oct 21 '22 00:10

Nick