github fork的本地克隆:如何保持同步?

时间:2014-08-25 17:42:37

标签: git github

1)在github上,我分叉了一个存储库以提交拉取请求。

2)然后我将存储库克隆到我的本地计算机。

3)然后我创建了一个分支,并对存储库中的一个文件进行了一些更改。

4)然后我认为在提交拉取请求之前我需要将本地存储库与原始存储库(我分叉的存储库)同步,所以我尝试了:

$ git remote -v
origin  https://github.com/7stud/sinatra.git (fetch)
origin  https://github.com/7stud/sinatra.git (push)
upstream    https://github.com/sinatra/sinatra.github.com.git (fetch)
upstream    https://github.com/sinatra/sinatra.github.com.git (push)

$ git fetch upstream

...但我收到的错误表明许多文件存在差异。我做了一些谷歌搜索,但我不打算进入所有文件并开始手动更改,所以我跳过了同步。

5)我设法将我的更改推送到我的github存储库,然后提交我的拉取请求。

6)拉取请求被接受了,所以我认为我应该将我的本地分支合并到我的本地主服务器中,并且可能尝试再次同步。

7)但我甚至无法在没有收到错误的情况下切换到我的本地分支:

$ git branch
  improve_readme
* master


$ git checkout improve_readme
.gitignore: needs merge
Gemfile: needs merge
README.md: needs merge
Rakefile: needs merge
error: you need to resolve your current index first

我需要做什么才能首先解决我当前的指数"?我在考虑提交另一个拉取请求。如果最简单的事情是在gihub上删除我的fork并删除我的本地克隆,那么重新分叉并重新克隆我就可以做到。

我刚刚再次尝试了以下内容:

$ git fetch upstream
$

这次我没有收到错误,但我也没有得到这样的输出:

# remote: Counting objects: 75, done.
# remote: Compressing objects: 100% (53/53), done.
# remote: Total 62 (delta 27), reused 44 (delta 9)
# Unpacking objects: 100% (62/62), done.
# From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY

我仍然无法切换分支机构:

$ git checkout improve_readme
.gitignore: needs merge
Gemfile: needs merge
README.md: needs merge
Rakefile: needs merge
error: you need to resolve your current index first

以下是更多信息:

$ git status
# On branch master
# Changes to be committed:
#
#   new file:   CNAME
#   new file:   Gemfile.lock
#   new file:   Thorfile
#   new file:   _config.yml
#   new file:   _includes/README.de.html
#   new file:   _includes/README.es.html
#   new file:   _includes/README.fr.html
#   new file:   _includes/README.html
#   new file:   _includes/README.hu.html
#   new file:   _includes/README.ja.html
#   new file:   _includes/README.ko.html
#   new file:   _includes/README.pt-br.html
#   new file:   _includes/README.pt-pt.html
#   new file:   _includes/README.ru.html
#   new file:   _includes/README.zh.html
#   new file:   _includes/sinatra-config-file.html
#   new file:   _includes/sinatra-content-for.html
#   new file:   _includes/sinatra-cookies.html
#   new file:   _includes/sinatra-decompile.html
#   new file:   _includes/sinatra-extension.html
#   new file:   _includes/sinatra-json.html
#   new file:   _includes/sinatra-link-header.html
#   new file:   _includes/sinatra-multi-route.html
#   new file:   _includes/sinatra-namespace.html
#   new file:   _includes/sinatra-reloader.html
#   new file:   _includes/sinatra-respond-with.html
#   new file:   _includes/sinatra-streaming.html
#   new file:   _layouts/contrib.html
#   new file:   _layouts/default.html
#   new file:   _layouts/post.html
#   new file:   _posts/2009-01-18-sinatra-0.9.0.markdown
#   new file:   _posts/2009-01-29-we-have-a-faq-now.markdown
#   new file:   _posts/2011-03-03-blog-revived.markdown
#   new file:   _posts/2011-03-03-sinatra-1.2.0.markdown
#   new file:   _posts/2011-07-21-sinatra-loves-dancer.markdown
#   new file:   _posts/2011-09-30-sinatra-1.3.0.markdown
#   new file:   _posts/2013-03-15-sinatra-1.4.0.markdown
#   new file:   about.markdown
#   new file:   api/index.html
#   new file:   blog.html
#   new file:   book.html
#   new file:   changes.html
#   new file:   configuration.markdown
#   new file:   contrib/config_file.html
#   new file:   contrib/content_for.html
#   new file:   contrib/cookies.markdown
#   new file:   contrib/decompile.html
#   new file:   contrib/extension.markdown
#   new file:   contrib/index.markdown
#   new file:   contrib/json.markdown
#   new file:   contrib/link_header.markdown
#   new file:   contrib/multi_route.html
#   new file:   contrib/namespace.markdown
#   new file:   contrib/reloader.markdown
#   new file:   contrib/respond_with.markdown
#   new file:   contrib/streaming.markdown
#   new file:   contributing.markdown
#   new file:   css/legend.css
#   new file:   css/print.css
#   new file:   css/syntax.css
#   new file:   documentation.markdown
#   new file:   example.markdown
#   new file:   extensions-wild.markdown
#   new file:   extensions.markdown
#   new file:   faq.markdown
#   new file:   feed.xml
#   new file:   images/favicon.ico
#   new file:   images/legend.gif
#   new file:   images/link-out.gif
#   new file:   images/logo.png
#   new file:   index.html
#   new file:   intro-de.html
#   new file:   intro-es.html
#   new file:   intro-fr.html
#   new file:   intro-hu.html
#   new file:   intro-ja.html
#   new file:   intro-ko.html
#   new file:   intro-pt-br.html
#   new file:   intro-pt-pt.html
#   new file:   intro-ru.html
#   new file:   intro-zh.html
#   new file:   intro.html
#   new file:   one-oh-faq.markdown
#   new file:   testing.markdown
#   new file:   wild.markdown
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   both added:         .gitignore
#   both added:         Gemfile
#   both added:         README.md
#   both added:         Rakefile
#

我想这就是为什么git不会让我切换分支。我不明白这些变化来自哪里。根据:

https://help.github.com/articles/syncing-a-fork

  

从上游存储库中获取分支及其各自的提交。提交给master将存储在本地分支,上游/主服务器。

但我没有任何名为upstream / master的本地分支:

$ git branch
  improve_readme
* master

master的上游更改是否自动与我的本地主服务器合并?

1 个答案:

答案 0 :(得分:0)

有一个非常棒的工具叫hub。它使用Github api调用挂钩标准git方法,使这样的事情变得非常简单。

我建议阅读git如何使用遥控器,但是如果你想要一个简单的方法将sinatra / master重新定位到你的分支中,请执行以下操作:

例如:

我克隆你的回购:

git clone https://github.com/7stud/sinatra.git
cd sinatra/

我在Sinatra的回购中打开了拉动请求:

https://github.com/7stud/sinatra/pull/2

然后我使用hub am工具从下载的diff中进行合并:

git am -3 https://github.com/7stud/sinatra/pull/2

它基本上为你完成了所有艰苦的工作。