I am using git for the first time and I am trying to make a commit. I want to ignore all .project and .settings files so I went to my .gitignore
file and added .project
, .settings
and saved. When I did that the .settings
file doesn't appear anymore, however, I still see my .project file when I do git -status
. Also, why is the .xml
and java
file in a different section that the .jar
files:

- 457
- 2
- 8
- 20
-
1My guess is that the `.project` file was already committed previously, either that or you somehow added it already. In any case, doing `git rm --cached .project` should fix that problem. As for why the `.xml` and `.java` file appear separately, Git is _tracking_ these files, and it's telling you that they were modified, but not yet staged. Stage them first using `git add
`, and then make your commit. – Tim Biegeleisen Mar 24 '17 at 02:25 -
@TimBiegeleisen THanks! But why are they in different sections if they both are unstaged? Shouldn't they all be listed in one section? – Robben Mar 24 '17 at 02:27
-
@TimBiegeleisen And yep it worked when I did `git rm --cached`. WHat does that command do ? – Robben Mar 24 '17 at 02:28
-
No. The "Untracked" files are basically files which Git is completely ignoring. From Git's point of view, they aren't there. The `.xml` and `.java` file _are_ being tracked (think: watched) by Git, but you haven't staged them yet. Unless you stage them, you cannot commit the changes. – Tim Biegeleisen Mar 24 '17 at 02:28
-
@TimBiegeleisen Gotcha. When I did `git rm --cached .project` and then I did `git add -A` and then `git status` I see that `.project` file is in the deleted. Why is that? I just want to exclude it, not delete it – Robben Mar 24 '17 at 02:33
-
It's not really deleted, it's only deleted from your Git repository. – Tim Biegeleisen Mar 24 '17 at 02:34
-
Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](http://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – 1615903 Mar 24 '17 at 07:11
1 Answers
Your git status
output is showing you two types of files:
- Changes not staged for commit
These are files which Git is tracking, and these files have been modified since the previous commit. But, the changes have not yet been staged. Unless you stage the changes using git add
, they will not be committed. Here is how you would stage the change to the web.xml
file:
git add path/to/web.xml
Assuming you really just started working, then the most likely explanation for why the .project
is showing up as being tracked by Git is that you somehow added it. To fix this, you can try using:
git rm --cached .project
This removes the .project
file from being tracked by Git. It would also remove it from the remote repository, but since you just started working and haven't pushed yet, this is a moot point.
- Untracked files
These are files which Git is completely ignoring. From Git's point of view, these files are not there. I can see that you have a number of JAR files listed as untracked, which is probably a good thing, since in general it is a bad idea to add binary files, especially dependencies, to your Git repository. Should you see a source file listed as untracked, you could also run git add
to add that file to Git.
The reason it is generally considered bad practice to add binaries to a Git repository is that Git doesn't handle diffs of binaries very well. Suppose you add a 1MB JAR file. Each time it changes, which could be fairly often if you are doing some open source stuff, a diff has to be stored for that binary. But, Git often will interpret the diff as being deleting the old file and replacing it with the entire contents of the new file. In other words, Git basically versions the entire binary for each change. Over time, this can cause your repository to become large and bloated, and it can be difficult to get rid of those binaries from your history. So, unless absolutely necessary, avoid storing binaries in your Git repository.

- 502,043
- 27
- 286
- 360
-
Thanks! Regarding your last point, i.e. the jar files. I need to commit those jars, is it bad practice to commit jars files ? – Robben Mar 24 '17 at 02:38
-
You almost certainly _don't_ need to commit those JAR files. Typically, JAR files are maintained and versioned by a tool like Maven or Gradle. Let a public JAR repository worry about versioning those, not Git. When you add binaries to a Git repository, you can create a world of problems. – Tim Biegeleisen Mar 24 '17 at 02:40
-
I see! Thanks so much for pointing that out. We don't use maven nor gradle for this project. We only use ant. I will be speaking to my manager about that. – Robben Mar 24 '17 at 02:43