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.
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.
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.
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).
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.
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.
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.
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.
You can also just ignore /build/, that will ignore only the folder called build, no files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With