Cant add target folder to .gitignore - java

I have Spring module project on Bitbucket with 2 Spring Boot apps in it. In the root module I have the .gitignore file and in every app I have .gitignore file with this content :
config.properties
.classpath
.project
.settings/
.idea/
target/
*.iml
I tried pulling project again but no changes.
Config.properties do get ignored but target folder isn't. Every time I make some change, I get target folder file in my git changes list.

There are a couple possibilities that come to mind.
Ensure that you haven't yet committed the target/ folder. This would prevent the gitignore from doing its job and ignoring the added folder.
The other thought is you have a multi-module project. Ensure you are calling the correct target/ folder to ignore: How to .gitignore files recursively

The new patterns in the gitignore donĀ“t work for existing directories.
Make sure to remove the existing entries in the git for the target folders:
git rm -r --cached etplans-web/target

Make sure that your "target/" folder path is correct. Look for examples here

i think its because you've accidentally added a file in target directory and so git doesn't ignore it.
hope this would help

Related

how to remove unwanted files from maven project

I am currently working with a spring web project. In my project, i am using git,maven and eclipse as IDE. when viewing git status in terminal these three files are present in all cases:
.classpath
.gitignore
.settings
how can in remove these unwanted files. i have no idea how these present in my project. my colleagues have also experiencing this issue.
any suggestions will be helpful.
As its a git repository, you can include below lines in your .gitignore file and then commit your .gitignore file to your central git repository, after that your local git repository won't show the ignore files which you added.
.settings
.classpath
Read more about .gitignore here https://help.github.com/articles/ignoring-files/.
Edit :- You these files are already unchecked then you need to run below command (If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:) :-
git rm --cached FILENAME
So in you case above command will look like git rm --cached .classpath and git rm --cached .settings.
Create .gitignore file in your project root directory and specify file path you want to untrack, for example:
.classpath
.project
.settings
target/
.mvn/
As other guys mentioned - you should add .gitignore file to the root of the project. There is a good Github project - gitignore. You could concat this files into one:
Java.gitignore
Maven.gitignore
Eclipse.gitignore
You could read more about .gitignore in a project description
You can directly open your workspace and open your project, after that you can manually delete those files... Make sure you check "show hidden files" if you are using windows and before deleting please close eclipse and then remove the files.
In SVN Repository can use Add to svn:ignore. using this one can remove unwanted files.

Add .jar files into a git repository

I have a project on eclipse where recently i created a new folder called lib and added some .jar files inside.
I cannot seem to commit the changes to git. It just doesnt appear in the tracked list of files..
I have removed .jar from .gitignore in my branch and commited the changes, and still the same.
The way I got it working for me was -
git add --force /path/to/the/NAME_Of_THE_JAR.jar
in the .gitignore file present in your project, you need to make sure that you allow *.jar files to be pushed. In my case, *.jar files was listed in ignore list. So I removed it from that list and git was able to detect it and I was able to push it.
You put your files in the project package, but you didn't put them under version control. All you need is to add them to VCS by "git add" command. Here is good documentation.
You should use this command in git bash or in terminal (if you have added git to path)
Also I recommend you to use build manager as Maven, Gradle or Ant to add you dependencies. Good luck!
You can identify if your .jar is needed to be added using the command git diff, git will indicate if you need to add the files to your repository.
Them use git add . and your files will be available for commit.
If the lib folder is ignored by .gitignore you can force adding them to the VCS using the following command:
git add /path/to/lib -f

How to not push certain directories/files to Github?

Specifically for Java Eclipse projects.
Is there a reason to have anything other than src and lib directories on github??
How much value does providing /bin, /settings .classpath, .project, etc.??
I'd like to have them on my local, but not displayed on github. Is there a way to do this?
Thanks!
EDIT:
contents of my .gitignore file (which is located in my local git project directory):
bin/
.settings/
.classpath
.project
I did a git add (to add this new .gitignore file) and a git commit to my local repo.
However, when I push to my remote github (https://github.com/VKkaps/Breakout) now, I still see everything including the .gitignore file now? Help?
The answer is .gitignore file.
See: https://git-scm.com/docs/gitignore for more information.
If you don't want the .gitignore file in the repo another option is Git's exclude file. This file works similar to a .gitignore file but isn't committed to the repo.
From the Github docs:
You can use this technique for locally-generated files that you don't
expect other users to generate, such as files created by your editor.
Use your favorite text editor to open the file called
.git/info/exclude within the root of your Git repository. Any rule you
add here will not be checked in, and will only ignore files for your
local repository.
In Terminal, navigate to the location of your Git repository Using
your favorite text editor, open the file .git/info/exclude Add rules
to the exclude file as you would the .gitignore file

Indecision on which files to upload on GitHub

I have a java project made with Eclipse.
While working on a project, Eclipse creates a bunch of files and folders, what folder and files should I upload on GitHub?
I think that everything under the src folder should be uploaded. Am I right? Should I commit the .java or the .class files?
source control such as git are used to commit anything that can be called as source and not environment specific. So code, related resources should go but any IDE specific files.
Use gitignore either project specific or globally. The easiest way is to create a .gitignore file in your project root repository. For instance
# Eclipse
.classpath
.project
.settings/
# Intellij
.idea/
*.iml
*.iws
out/
artifacts/
# Mac
.DS_Store
# Maven
log/
target/
It depends on which files do you want to share too.
For example, in my current company almost all my colleagues and I use Eclipse, so we have repositoried .project" and .classpath too. It is very handy because changes in .classpath are done only once, and then propagated to all developers.
If your root folder is both the git repo root and your workspace, you won't probably want to upload the .metadata folder, since it contains settings specific to each different developer. And, by all means, you will want to ignore Eclipse's compiled directory (typically /bin).
Think about what do you want to share and/or version, and that will probably give you a list of things to upload/ignore.
Edit: as said before, upload ONLY .java files, .class files are products of your source code, and have to be generated, not stored.

Ignore Mercurial sub directories

I have a directory with my Maven projects in it. It looks like this:
.hg
.idea
parentProject
project1
.idea
docs
src
target
pom.xml
project2
.idea
docs
src
target
pom.xml
target
pom.xml
.hgignore
I want to ignore the .idea and target directories in all my project. I have included the .idea and target directories into .hgignore but it only ignores those directories in the which .hgignore file is. This means that only in root directory .idea and target is ignored.
If I add .hgignore file in all sub projects this does not changes anything files are still not ignored.
My ignore list looks like this:
build
dist
target
faces-config.NavData
.idea
.iml
How should I specify in the .hgignore to get the .idea and target ignored from everywhere?
try hgignore with regex
syntax: regexp
^\.idea$
^target$
How about something like **/.idea and **/target? Check out the possible patterns here.
You should not need to explicitly ignore target directory.
This problem will come if you have added it by mistake to Mercurial. Let's say you have done the following:
Created a project and compiled a few times (hence target directory
exist)
Decided to add source control to the project so you've
initialized a Mercurial repository and executed hg add command
(either implicitly or explicitly from the IDE). Bam! You have now
told Mercurial that target is a directory that should be included.
Trust me. I've been there !
To fix: Do the following from the command line:
hg forget target
When it comes to .idea directory I would think there's no other way than to use the .hgignore file but I'm puzzled why Intellij IDE doesn't add this automatically. (not a Intellij IDE user myself). That is the real question to ask.

Categories

Resources