我想在Eclipse中创建一个新的Maven项目,并将其推送到github上的新存储库中。我对实现这一目标的正确步骤有些困惑。


要使用Maven原型,我不能使用其中包含文件的目录。因此,我无法在git本地存储库中创建Maven项目。因此,使用原型可能应该是第一位的。
我还需要在我的github帐户中创建一个存储库。如果我通过github桌面应用程序执行此操作,则已经为我创建了本地存储库。
现在,我有一个Eclipse项目和一个本地存储库,到目前为止还没有关系。我应该如何“关联”它们?


我发现了很多有关从github进行克隆的信息,但是我的github存储库还没有Maven项目,因此无法导入Eclipse。如果我改用命令行而不是空目录,则由于目录不为空,因此无法再应用Maven原型。

我很困惑。有人可以使我困惑吗?

最佳答案

创建一个新的Maven项目(但是要创建它)。当然,这将在文件系统中使用所有资源创建一个新目录。
Create a repository in Github
从命令行(位于项目目录内)执行git init。这将在该目录中创建本地存储库。
接下来,add a remote到本地存储库:$ git remote add origin https://github.com/user/repo.git(可以选择将origin替换为将要调用的远程存储库的名称,还将user替换为github用户名,将repo替换为github的名称仓库名称)
将所有要提交的文件添加到本地存储库中。


例如

$ git add .

# Adds the file to your local repository and stages it for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.



提交更改。


例如:

$ git commit -m "Add existing file"
# Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.



Push to remote


请注意,以以下结构为参考,我建议的是将project1project2projectN目录中的任何目录作为git存储库,而不是整个worspace(/roo_dir/workspace/目录)。

/roo_dir/workspace/
            - project1
            - project2
            - projectN


其他读物:


Considerations for Git Repositories to be used in Eclipse
Should I store git repository in Home or Eclipse Workspace?
Is it better to keep Git repository inside or outside of Eclipse workspace?

08-05 16:08