git Egit:设置 gitignore 忽略所有 eclipse 项目文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35114228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Egit: Set gitignore to ignore all eclipse project files
提问by vedi0boy
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
我在 github 上有一个项目,我想从中删除所有与 eclipse 相关的文件,并允许克隆它的人使用他们想要的任何 ide。这是项目: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.
我必须在我的 gitignore 中放入什么?我对整个版本控制管理器仍然很陌生,因此您不必确切地告诉我该放什么,但可以解释它是如何工作的以及要注意什么,以便它仍然可以工作。
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.
顺便说一下,它使用 gradle,所以我也希望它保持与 gradle 相关的文件保持不变,因为克隆人将需要它们来构建项目,我计划删除“API”文件夹并仅使用 gradle 依赖项。
回答by nazar_art
For excluding configuration files you have to configure .gitignore
to something as follows:
要排除配置文件,您必须进行.gitignore
如下配置:
# 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
git rm --cached .project
For a directory:
对于目录:
git rm --cached -r target
git rm --cached -r 目标
回答by Matthias Herlitzius
One of my .gitignore
files looks like this:
我的.gitignore
文件之一如下所示:
/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.:
您可以在例如 GitHub 上查看其他项目,以激发您可能想要放入的内容.gitignore
,例如:
- https://github.com/spring-projects/spring-framework/blob/master/.gitignore
- https://github.com/spring-projects/spring-social/blob/master/.gitignore
- 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.
但是,我认为我上面的例子应该足以开始。
回答by Felix Novovic
Add all the eclipse files to the .gitignore and, to remove them from the remote repository, you will have to
将所有 eclipse 文件添加到 .gitignore 中,要从远程存储库中删除它们,您必须
git rm (-r) --cached eclipseProjectFile
The above command will remove the file from the repo, but not from your machine.
上面的命令将从 repo 中删除文件,但不会从您的机器中删除。
回答by Musa
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.
1 - 在您的 GIT 项目根目录上创建 .gitignore 文件(您在其中输入了“git init”(靠近 .git 目录))。注意到 nazar_art 的内容,或者您可以添加一些其他模式以进行忽略。
2 - git rm -r --cached file_1 file_n directory_1 directory_n
...
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 :))"
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]
4 - git push -u origin --all
(这将同步你的远程(源)repo 的所有分支)或者你可以输入 git push [remote] [branch]
i know it is late. but may be helpful somebody who just beginning
我知道已经晚了。但可能对刚开始的人有帮助
回答by Vishnu Dahatonde
This is general answer to ignore any file extension from git staging. 1. In Eclispe go to windows->preferences->git-> ignore resources (you can simply search "ignore resources"). 2. check any class extension that you want to avoid staging in git staging area. 3. if you do not find your extension there, you have option to add any extension that you need to ignore.
这是忽略来自 git staging 的任何文件扩展名的一般答案。1. 在 Eclispe 中,转到 windows->preferences->git-> ignore resources(您可以简单地搜索“ignore resources”)。2. 在 git 暂存区检查要避免暂存的任何类扩展。3. 如果您在那里找不到您的扩展名,您可以选择添加任何您需要忽略的扩展名。