How do I prevent .git directory from getting copied to bin directory during rebuild?

老子叫甜甜 提交于 2019-12-06 01:55:32

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.

VonC

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!