How do I prevent .git directory from getting copied to bin directory during rebuild?
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.)
4 Solutions collect form web for “How do I prevent .git directory from getting copied to bin directory during rebuild?”
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:
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.
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
If that is the case:
git submodule deinit bin git rm bin git commit -m "remove bin submodule" git push
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.