如何配置 Eclipse 以将现有 git 存储库与现有源代码一起使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16727709/
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 do I configure Eclipse to use an existing git repository with existing source code?
提问by wchargin
I have Eclipse Juno with EGit and a project that I've been working on for a while. I've decided to move it to Git, so I created a Github account and downloaded and installed the program. The repository is at C:\Users\username\GitHub\project_name\
, but all it has is the README.md
file.
我有带有 EGit 的 Eclipse Juno 和一个我已经工作了一段时间的项目。我决定将其移至 Git,因此我创建了一个 Github 帐户并下载并安装了该程序。存储库位于C:\Users\username\GitHub\project_name\
,但它只有README.md
文件。
How can I configure Eclipse to use my existing source code (in a workspace separate from the git folder) to work well with git? I've tried using Window→ Show View→ Otherand selecting "Git Repositories," but other than adding a repository (which I have done) I can't figure out how to sync the code.
如何配置 Eclipse 以使用我现有的源代码(在与 git 文件夹分开的工作区中)以便与 git 一起工作?我尝试使用Window→ Show View→ Other并选择“Git Repositories”,但除了添加存储库(我已经完成)之外,我不知道如何同步代码。
I've read this questionbut I get the impression that those answers will perform a one-time commit, instead of a sync.
我读过这个问题,但我的印象是这些答案将执行一次性提交,而不是同步。
To clarify:The repository does not have any code. I would like my existing code (in the Eclipse workspace) to be synced to the new repository.
澄清:存储库没有任何代码。我希望将我现有的代码(在 Eclipse 工作区中)同步到新的存储库。
采纳答案by anand.trex
If you already have a git repository in place, first copy all your files to that directory (yes, manually) and do a git commit -a
to commit all the files into the repository. I'm assuming here that you've already initialized the repository at C:\Users\username\GitHub\project_name\
with git init
.
如果您已经有一个 git 存储库,首先将所有文件复制到该目录(是的,手动),然后执行 agit commit -a
将所有文件提交到存储库中。我在这里假设您已经C:\Users\username\GitHub\project_name\
使用git init
.
In eclipse, go to File→ Switch Workspace→ Other...and point it to a workspace of your choice that can be completely different than the location of your code, or your earlier workspace. In fact, don't point it to the directory which contains your git repository.
在 eclipse 中,转到File→ Switch Workspace→ Other...并将其指向您选择的工作区,该工作区可能与您的代码或早期工作区的位置完全不同。实际上,不要将其指向包含 git 存储库的目录。
Once you have a clean workspace, go to File→ New→ Other..., select Git→ Git Repositoryand enter the path of your git repository (C:\Users\username\GitHub\project_name\
). Enter a name for the repository, and click Finish.
有了干净的工作区后,转到File→ New→ Other...,选择Git→ Git Repository并输入 git 存储库的路径 ( C:\Users\username\GitHub\project_name\
)。输入存储库的名称,然后单击完成。
I would really recommend you read at least the first few chapters of the git bookto understand how git works, and to help you push and pull code to and from remote repositories.
我真的建议您至少阅读git 书的前几章,以了解 git 的工作原理,并帮助您向远程存储库推送和拉取代码。
If your existing repository is not git, you're going to have a hard time keeping the directories in sync. You might want to setup rsyncto sync the directories. There is no way AFAIK for eclipse to automagically keep the two repositories in sync.
如果您现有的存储库不是 git,您将很难保持目录同步。您可能想要设置rsync来同步目录。Eclipse 的 AFAIK 无法自动保持两个存储库同步。