3

A .git directory keeps reappearing in my project, inside a directory that I think should be ignored. It reappears each time I clean the project or refresh it in Eclipse. The duplicated .git directory results in redundant files that prevent the project from building.

I have an Android project in Eclipse that links source from a Java project, which is the way LibGDX handles a project. The .git directory that I don't want contains a file that causes a conflict, so I have to delete it every time I want to build to device.

It is creating the directory MyProject/bin/classes/.git. But I have bin/ in my .gitignore file. My repository is in MyProject.

The conflicting file is \bin\classes.git\COMMIT_EDITMSG. This conflicts with a file in my linked source Java project: \gen.git\COMMIT_EDITMSG. Also the same issue, because I have \gen in the .gitignore of that project.

I am pretty sure either Eclipse or ADT that is copying the .git directory over to the bin directory when it rebuilds or cleans the project.

So my question now is, how do I get Eclipse and/or ADT to stop doing that?

(If you want to see my old .gitignore, which I think is irrelevant because it was set up correctly to ignore the bin directory, you can click the "Edited" link to see it in this post's history.)

Tenfour04
  • 83,111
  • 11
  • 94
  • 154

4 Answers4

2

If what you want is to exclude *.git file to be copied during the build in eclipse, you can set this under Java Build Path menu for that specific project, and then add *.git into the exclusion patterns. It is quite tricky here because you can either specify inclusion patterns, or exclusion patterns, but not both of them. So, maybe you want to try to exclude *.git so that it does not copy during build.

See screenshot below for example:

enter image description here

  • This solved my problem when I did it from within the linked source folder. Thank you! I've been suffering with this issue for a year! – Tenfour04 Jun 06 '14 at 00:56
2

You need to edit the .classpath file for your project and add patterns to ignore these directories.

Look for the lines:

<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>

and change them into:

<classpathentry excluding="**/.git/**" kind="src" path="src"/>
<classpathentry excluding="**/.git/**" kind="src" path="gen"/>

The double asterisks are important, since they mean "any number of folders" (in this case "no matter what parent(s)" and "no matter what child(ren)" respectively).

Take a look at Inclusion and Exclusion Patterns in the Eclipse documentation.

matiash
  • 54,791
  • 16
  • 125
  • 154
  • Thanks, this was similar to the accepted answer, but the other answer was earlier and a little easier to implement. And I was linking the source of a project that was also linking source, which made this choke when I added the `gen` path. – Tenfour04 Jun 06 '14 at 00:58
1

Are you using submodules? – torek Jul 23 '13 at 20:27

I don't know what that is, so I don't think so

You should check it anyway, by going to the parent folder of that .git directory, and doing a git ls-files, looking for a special entry (a gitlink) mode 160000.

cd MyProject
git ls-tree HEAD bin
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398  bin

As jthill suggests in the comments:

git ls-files -s|grep ^16

See also if you have a MyProject/.gitmodules file.

If that is the case:

git submodule deinit bin
git rm bin
git commit -m "remove bin submodule"
git push
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • s/can/should/. I'd `git ls-files -s|grep ^16` myself. +1, also [that clone submodules checkbox](http://wiki.eclipse.org/EGit/User_Guide#Working_with_Submodules) looks good for this. – jthill Jun 01 '14 at 14:39
  • @jthill I agree, and have edited the answer accordingly. – VonC Jun 01 '14 at 15:00
0

Adding a file to .gitignore does not remove it if it's already in the tree:

$ git init
Initialized empty Git repository in <path>/.git
$ mkdir gen; echo created > gen/file
$ git add gen; git commit -m initial
[master (root-commit) 14c2756] initial
 1 file changed, 1 insertion(+)
 create mode 100644 gen/file
$ echo gen > .gitignore; git add .gitignore; git commit -m 'oops, ignore gen'
[master dc55e75] oops, ignore gen
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore
$ rm gen/file
$ git reset --hard HEAD
HEAD is now at dc55e75 oops, ignore gen
$ cat gen/file
created
$ git ls-files
.gitignore
gen/file

So, how do you fix it?

$ git rm gen/file; git commit -m 'remove gen that we ignore'
rm 'gen/file'
[master 97de6f9] remove gen that we ignore
 1 file changed, 1 deletion(-)
 delete mode 100644 gen/file
$ mkdir gen ; echo created > gen/file
$ git status
# On branch master
nothing to commit, working directory clean

Basically you have to commit a change that removes the to-be-ignored files, so that they're not in the tree. After that, the combination of the .gitignore and the lack of in-tree files will set you up the way you wanted in the first place.

torek
  • 448,244
  • 59
  • 642
  • 775
  • I don't think this is my specific issue. That bin/ directory was already in my .gitignore before I created the repository. Also, I have now deleted the repository in the top level of the project by deleting the .git directory there. But when I clean the project in Eclipse, the .git directory in bin/ reappears! – Tenfour04 Jul 23 '13 at 11:52
  • It might be something else. Are you using submodules? – torek Jul 23 '13 at 20:27
  • I don't know what that is, so I don't think so. – Tenfour04 Jul 24 '13 at 00:55