如何从 Eclipse 中现有的 maven 项目创建一个 git 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30995189/
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
How to create a git project from an existing maven project in Eclipse?
提问by user697911
I have a local maven project. Now I want to put it into a git repository. I think I first need to create a local git project and then push all to the remote repository. Is there a way to do this in Eclipse? I have the egit plugin in Eclipse.
我有一个本地 Maven 项目。现在我想把它放到一个 git 存储库中。我想我首先需要创建一个本地 git 项目,然后将所有内容推送到远程存储库。有没有办法在 Eclipse 中做到这一点?我在 Eclipse 中有 egit 插件。
Tried the following step:
尝试了以下步骤:
1) Create a local new Git repository and add it to this view
2) There are 3 options:
* Import Maven Proejcts
* Import existing proejcts
* Import as a general project
None of these seem works. This should be a very typical use case. First, you create a maven locally, without git. At some point, you want to put it into a git repository and collaborate with others. How to achieve this?
这些似乎都不起作用。这应该是一个非常典型的用例。首先,您在本地创建一个 Maven,没有 git。在某些时候,您想将其放入 git 存储库并与其他人协作。如何实现这一目标?
回答by nwinkler
Unless you absolutely want to do this in Eclipse - it's probably easier and quicker to do this from the command line. Open a terminal/shell/command window in your project directory and then do the following:
除非您绝对想在 Eclipse 中执行此操作 - 从命令行执行此操作可能更容易和更快。在项目目录中打开终端/shell/命令窗口,然后执行以下操作:
git init
That's it... You will now have a local empty Git repository.
就是这样...您现在将拥有一个本地空 Git 存储库。
Before you commit anything, think about adding a .gitignore
file to ignore files that don't belong in the repo. Here's a good starting point: https://github.com/github/gitignore/blob/master/Global/Eclipse.gitignore
在提交任何内容之前,请考虑添加一个.gitignore
文件以忽略不属于 repo 的文件。这是一个很好的起点:https: //github.com/github/gitignore/blob/master/Global/Eclipse.gitignore
Please note that this ignores the .project
and .classpath
files - some people prefer to share these with other developers.
请注意,这会忽略.project
和.classpath
文件 - 有些人更喜欢与其他开发人员共享这些文件。
Once you have added some files and committed them, you can add a remoteto point to the remote repository.
添加一些文件并提交后,您可以添加一个远程文件以指向远程存储库。
In the long run, it makes sense to get familiar with the command line, even when using an IDE like Eclipse. Many things are easier from the IDE once it's set up (like reviewing changes, history, etc.), but simple tasks like adding files, committing changes or similar are sometimes easier done from the command line.
从长远来看,熟悉命令行是有意义的,即使在使用像 Eclipse 这样的 IDE 时也是如此。IDE 设置后,许多事情在 IDE 中变得更容易(例如查看更改、历史记录等),但有时从命令行更容易完成添加文件、提交更改或类似任务等简单任务。
回答by siegi
Right clicking the project, Team, Share project…allows you to initialize a Git repository for your project.
右键单击项目、Team、Share project...允许您为您的项目初始化 Git 存储库。
回答by questionaire
I would expect to get it working with the following steps: 1. right-click on your project, select Team → Share Project → Git 2. Commit Changes 2. push to remote
我希望通过以下步骤使其工作: 1. 右键单击您的项目,选择 Team → Share Project → Git 2. Commit Changes 2. push to remote
Other workaround might be, import as git project, right klick on it -> configure -> enable maven
其他解决方法可能是,导入为 git 项目,右键单击它 -> 配置 -> 启用 maven
回答by Santhosh Gandhe
Run the following command with passing your project directory
运行以下命令并传递您的项目目录
git init
混帐初始化