how can i ignore the .idea folder in .gitignore file? - java

I ignored the .idea folder(for intellij IDE), all file and folder that is in the .idea is removed. I am seeing the .idea in intellij but no this folder in github. And also when i clone this project there is no again .idea, because of it this project is not working on intellij idea project. I am not adding new developer.

Git doesn't track directories, it tracks only files. When you untrack all files from within a directory, you are in essence untracking the directory as well.
If you want to keep the directory around in your repository on other machines, while ignoring all the files within it, you could add an empty dummy .gitkeep file.
However, since the desired behavior is to not track any files within the directory, we can use a directory specific .gitignore as the dummy file here which has a single ignore rule for ignoring everything.
So, basically, this translates into the following commands:
$ cd $PROJECT_DIR
$ echo "*" >> .idea/.gitignore
$ git add -f .idea/.gitignore && git commit -m "Ignoring all files within .idea"

Related

Cant add target folder to .gitignore

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

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.

Egit: Set gitignore to ignore all eclipse project files

I have a project up on github and I want to remove all eclipse related files from it and allow people who clone it to use any ide they want. Here is the project: https://github.com/vedi0boy/Archipelo
What would I have to put in my gitignore? I'm still very new to the whole version control manager thing so you don't have to tell me exactly what to put but maybe explain how it works and what to be careful about so that it will still work.
By the way, it uses gradle so I would also like it so that the gradle related files remain untouched since cloners will need them to build the project and I plan to remove 'APIs' folder and just use gradle dependencies.
For excluding configuration files you have to configure .gitignore to something as follows:
# Eclipse
.classpath
.project
.settings/
# Intellij
.idea/
*.iml
*.iws
# Mac
.DS_Store
# Maven
log/
target/
And, only after this, you have to push your project because now you have to push your configuration to the remote repo.
And you can not delete it locally and push. You have to delete it from remote repo only:
git rm --cached .project
For a directory:
git rm --cached -r target
One of my .gitignore files looks like this:
/bin
/.classpath
/.project
/.settings
/target
You can look at other projects at e.g. GitHub to let you inspire what you might want to put into your .gitignore, e.g.:
https://github.com/spring-projects/spring-framework/blob/master/.gitignore
https://github.com/spring-projects/spring-social/blob/master/.gitignore
However, I think my example above should be sufficient to start with.
Add all the eclipse files to the .gitignore and, to remove them from the remote repository, you will have to
git rm (-r) --cached eclipseProjectFile
The above command will remove the file from the repo, but not from your machine.
1 - create .gitignore file on your GIT project root direcotry (where you have typed "git init" (near .git directory) ). With content of nazar_art noticed or you can add some other pattern for ignore.
2 - git rm -r --cached file_1 file_n directory_1 directory_n ...
3 - git commit -m "removed some files and directories from remote repo and created gitignore :))"
4 - git push -u origin --all (this will synch all branch of your remote (origin) repo) or you can type git push [remote] [branch]
i know it is late. but may be helpful somebody who just beginning
This is general answer to ignore any file extension from git staging.
In Eclipse go to windows->preferences->git->ignore resources (you can simply search "ignore resources").
Check any class extensions that you want to avoid staging in git staging area.
If you do not find your extension there, you have the option to add any extension that you need to ignore.

Java directory structure on github

My bin directory is currently being untracked; however, I would like that to be part of the repo as it contains the binary file to execute the program. On the other hand, the build directory is being tracked, which I do not want. How can I add the bin directory and remove the build directory?
How can I add the bin directory and remove the build directory?
First part:
$ echo build/ > .gitignore
$ git commit .gitignore -m"Add .gitignore"
This will ensure that build changes won't be tracked from now on.
Second part:
$ git rm -r --cached build
$ git commit -m"Remove build/ from tree"
This will remove build from the index, but not the working directory.
Third part:
$ git commit bin -m"Added bin"
Although you really should NOT do that; rather, you should be able to build bin from your project.
If the structure of your project is like this (and is in a folder called MyProject):
|- MyProject
|-bin
|-build
Then to stop tracking build, you'll want to add a line to a file called .gitignore in MyProject. To add the bin folder, you can simply do from the MyProject folder:
git add bin
^^ assuming there's currently at least one file in bin. Once added, you can commit as normal.
As fge has pointed out, think a while before adding the bin folder. If the binary file within it can be created from the source code, then someone who clones your repository can do that themselves. Committing binary files is not usually what we want to do, because if they change regularly, then they will cause the size of the repository to grow quickly, among other things.

Eclipse: Remove Eclipse generated .class and .project files

I have a Java project with SVN version control system. My IDE is eclipse. Iniitally when I open the project, I edited something. Since this is team project. Someone else commit his own .class and .project file into svn. When I pointed out, he removed .class and .project in some particular sub projects. Anyway, I have .class and .project in all sub projects. Now I want to a clean environment, I want to delete all .class and .project files. Are there some script available in this forum?
You didn't mention what OS are you using... If it's linux you can do it in commandline like that:
find /the/path/to/your/project -name ".class" -exec rm {} \;
If you have a unix like environment then 'find' from a command line could do it. First cd to the project directory then
find . ( -name *.class -or -name .project ) -delete
Are you using Maven as a build tool? What is your directory structure.
Any bin, out, target etc. directories should be on ignore list in SVN. You can use "add to ignore list" in Tortoise SVN or edit folder properties and set "svn:ignore" property. This you can do recursively. Mind that this will affect other developers too.
If you're not using Maven, deleting .project and .classpath might cause some trouble. There might be some project-specific settings set. Blindly deleting .project files is not a solution. If you use Maven, you can definetely delete .project, .classpath and .settings, add them to ignore list and re-import all proejects with m2e plugin.

Categories

Resources