git GitHub 和 Eclipse 入门(spring 源工具套件 2.7.1)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6720204/
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
Getting started with GitHub and Eclipse (spring source toolsuite 2.7.1)
提问by Shamaila Tahir
I am new with both Git and GitHub so please bear with me. I have an empty repository on GitHub with an automatically created branch (gh-pages), which, I understand, is supposed to be used with GitHub's pages functionality.
我是 Git 和 GitHub 的新手,所以请耐心等待。我在 GitHub 上有一个空存储库,其中有一个自动创建的分支 (gh-pages),据我所知,它应该与 GitHub 的页面功能一起使用。
Now what I would like to do is to create and eclipse project from which I could commit/push to this repository.
现在我想做的是创建和 eclipse 项目,我可以从中提交/推送到这个存储库。
What is confusing me that I can't see any option to create a remote branch on github. I suppose pushing my source to gh-pages won't be a good idea. BTW, I also don't understand why the GitHub pages is feature is implemented as a branch? Aren't branches supposed to be merged with each other at some point. Clearly it wouldn't make any sense to merge github pages into my project. Wouldn't it be better to have a folder within my project for this purpose.
令我困惑的是,我看不到在 github 上创建远程分支的任何选项。我想将我的来源推送到 gh-pages 不是一个好主意。顺便说一句,我也不明白为什么 GitHub 页面的功能是作为分支实现的?分支不应该在某个时候彼此合并。显然,将 github 页面合并到我的项目中没有任何意义。为此,在我的项目中有一个文件夹不是更好吗?
I googled and found this linkbut being a git noob I am not sure if that's what I want to do. I would like to use Eclipse as my primary interface to git and github only falling back to command line or other interfaces when there is no other option.
我用谷歌搜索并找到了这个链接,但作为一个 git noob 我不确定这是否是我想要做的。我想使用 Eclipse 作为 git 和 github 的主要接口,只有在没有其他选择时才回退到命令行或其他接口。
OK I think I have figured it out. Basically, what you need is to define a remote ref that need not exist before hand.
好吧,我想我已经想通了。基本上,您需要的是定义一个不需要事先存在的远程引用。
- Create a project
- Team->Share it to a local repository
- In the repository view (Window->Show View-> Git -> Repositories) select the local repository and right click on remotes
- Select new remote (configure push). Type origin in the remote name. Press OK
- Change URL. Copy/paste the ssh uri from github. Select ssh protocol (make sure you have ssh key defined in eclipse SSH preferences, and uploaded to github)
- Now the last part is to add Ref mapping. Click on Add.. in ref mapping section of screen. And enter refs/heads/master in both local and remote branches.
- 创建项目
- 团队->将其共享到本地存储库
- 在存储库视图(窗口->显示视图-> Git -> 存储库)中选择本地存储库并右键单击远程
- 选择新遥控器(配置推送)。在远程名称中键入 origin。按确定
- 更改网址。从 github 复制/粘贴 ssh uri。选择 ssh 协议(确保你在 eclipse SSH 首选项中定义了 ssh 密钥,并上传到 github)
- 现在最后一部分是添加 Ref 映射。在屏幕的 ref mapping 部分单击 Add..。并在本地和远程分支中输入 refs/heads/master。
Or may be the refs/heads/master on both side isn't a good idea :) I see, cloning a github repo that doesn't have gh-pages branch is simpler as it automatically creates this remote fetch spec
或者两边的 refs/heads/master 都不是一个好主意 :) 我明白了,克隆一个没有 gh-pages 分支的 github repo 更简单,因为它会自动创建这个远程获取规范
Remote Fetch Specification +refs/heads/*:refs/remotes/origin/*
远程获取规范 +refs/heads/*:refs/remotes/origin/*
Maybe this is what I need to enter in the step 6 above
也许这就是我在上面的第 6 步中需要输入的内容
Ok as it turned out the original idea of "refs/heads/master in both local and remote branch" was correct. Pushing with this configuration is showing my changes in git hub correctly. The second option on the other hand is failing silently.
好的,因为结果证明“本地和远程分支中的 refs/heads/master”的原始想法是正确的。使用此配置推送正确显示了我在 git hub 中的更改。另一方面,第二种选择是默默地失败。
采纳答案by Ryan Stewart
Branches typically are used in the way you described, but nothing says they mustbe used that way. This is just the way github chose to let you manage your page content, and it works quite well. It's kind of similar to hosting multiple repos on one SVN server.
分支通常以您描述的方式使用,但没有说它们必须以这种方式使用。这正是 github 选择让您管理页面内容的方式,而且效果很好。这有点类似于在一台 SVN 服务器上托管多个存储库。
As for creating new repos, if you create a repo in github and then clone it, you'll have an empty repo locally that already points to github with a remote named "origin". This is a convenient way to start out, since you don't have to mess with adding a remote yourself. At this point, your repo has no commits and no branches in it. When you make the first commit, it will automatically establish a branch named "master". I don't know how eclipse is set up by default, but from the command line with default settings, you have to explicitly push new branches to a remote or else they won't get pushed at all. I.e. making the first commit and doing git push
will just fail with a message like "No refs in common and none specified; doing nothing". Instead, you have to git push origin master
to tell it to establish the "master" branch in remote "origin" (aka github). Thereafter, just a git push
will work fine.
至于创建新的存储库,如果您在 github 中创建一个存储库然后克隆它,您将在本地拥有一个空存储库,该存储库已指向具有名为“origin”的远程的 github。这是一种方便的开始方式,因为您不必自己添加遥控器。此时,您的 repo 没有提交,也没有分支。当您进行第一次提交时,它会自动建立一个名为“master”的分支。我不知道默认情况下 eclipse 是如何设置的,但是从具有默认设置的命令行中,您必须明确地将新分支推送到远程,否则它们根本不会被推送。即进行第一次提交并执行git push
只会失败,并显示“没有共同的参考,也没有指定;什么都不做”之类的消息。相反,你必须git push origin master
告诉它在远程“原点”(又名 github)中建立“主”分支。此后,只需一个git push
就可以正常工作。
Hope that clears up some of your confusion.
希望能解决你的一些困惑。