在分支中跟踪某人的 GitHub 存储库
我对 Git 还很陌生,到目前为止非常喜欢它,但不确定在这里做什么。
我已经分叉了一个 github 项目,目前正在将其移植到另一种语言。作为参考,我创建了一个代码分支,就像我创建分支时一样。我现在的问题是原来的项目已经更新了,我不知道如何将这些更改从原来的 master 拉到我的分支中(因为“origin”指向我的 github 项目)。
关于我自己的教育的后续问题,原始项目的所有者必须运行什么命令才能将更改从我的分支拉到他的主分支中?
编辑:当我从自己的“主”分支运行它们时,这些答案有效,但当我从“跟踪”分支运行它们时则不起作用(我在这里松散地使用该术语,因为我知道同名的 git 命令。但不确定它的作用)。
当我在非主分支中运行 git fetch uploader 时,什么也没有发生。当我尝试 git fetchupstream:master 时,它说
ssh: upstream: no address associated with name
fatal: The remote end hung up unexpectedly
I'm pretty new to Git, and like it a lot so far, but am not sure what do do here.
I've forked a github project, and am currently in the process of porting it to another language. For reference, I've created a branch of the code as it was when I made the fork. My problem now is that the original project has been updated, and I can't figure out how to pull those changes into my branch from the original master (because 'origin' points to my github project).
Follow-up question for my own education, what command will the owner of the original project have to run in order to pull a change in from my branch into his master branch?
EDIT: These answers work when I run them from my own 'master' branch, but not when I run them from my 'tracking' branch (I'm using the term loosely here because I know of a git command of the same name. Not sure what it does, though).
When I'm in my non-master branch, and run git fetch upstream
, nothing happens. When I try git fetch upstream:master
, it says
ssh: upstream: no address associated with name
fatal: The remote end hung up unexpectedly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
git remote
添加原始存储库:(如果您愿意,您可以将其称为
upstream
以外的名称,但这是您用来引用远程的名称.)要获取更新,只需运行:
为了将更改从您的存储库获取到上游存储库,维护者必须将您的存储库添加为远程存储库,然后拉取更改:
或者,如果上游维护者不这样做想要将你的仓库添加为远程仓库,他可以直接引用它:
You can add the original repo using
git remote
:(You can call it something other than
upstream
if you want, but that's the name you'll use to refer to the remote.)To get updates, just run:
In order to get the changes from your repo into the upstream repo, the maintainer will have to add your repo as a remote, and then pull the changes:
Or, if the upstream maintainer doesn't want to add your repo as a remote, he can reference it directly:
您可以将其添加到远程存储库列表中并从中获取/拉取,
git pull
实际上会将first-repo-name master分支合并到您的master分支(如果您当前位于该分支中)在 GitHub 方面,这不是一个实际的命令,而是 您可能发起的拉取请求。
(来源:skitch.com)
从技术上讲,他可以将您的分叉回购作为远程回购添加到他的本地回购上(就像您上面所做的那样),但是如果他的回购严重分叉,这将变得不切实际,因此需要中央“拉取请求”机制。
You can add it to your list of remote repos and fetch/pull from it
the
git pull
will actually merge the first-repo-name master branch to your master branch (if you are currently in that branch)On the GitHub side, this won't be an actual command, but the result of a pull request you would have initiated.
(source: skitch.com)
Technically, he could add your forked repo as a remote repo on his local repo (like you did above), but if his repo is heavily forked, this becomes un-practical, hence the central "pull requests" mechanism.
Git 应该像这样工作,你将更改从你的源(无论是分叉的存储库,还是原始的)拉到你的本地主控中。然后,您可以使用 git-merge 或 git-rebase 将它们放入您的本地分支。一旦您对结果感到满意,您就可以推回遥控器。
我认为从您提出问题的方式来看,您最好在从原始存储库中提取更改后使用 git-rebase 在 master 上重新建立分支。
如果您尝试从命令行完成所有这些操作,您将需要学习 git-cherry。否则,像 gitx 或 gitk 这样的工具对于选择要合并的提交非常有帮助。
Git is supposed to work like this, you pull the changes from your origin (be it the forked repo, or the original) into your local master. You would then use git-merge or git-rebase to get them into your local branch. Once you're happy with the result you can push back to the remote.
I think from the way you asked the question that you would be best off using git-rebase to rebase your branch on the master after you've pulled the changes from the original repo.
If you try to do all this from the commandline you're going to need to learn git-cherry. Otherwise tools like gitx or gitk are very helpful to select commits you want to merge.
Github 的分叉帮助很好地解释了这一点:
http://help.github.com/forking/
Github's forking help explains it pretty well:
http://help.github.com/forking/