github fork:你的分支是5承诺如何在不推送的情况下清理它 [英] github fork : your branch is 5 commits ahead how to clean this without pushing

查看:71
本文介绍了github fork:你的分支是5承诺如何在不推送的情况下清理它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在github上创建了一个项目,以发送请求请求.问题是我的工作方式非常肮脏.

I forked a project on github, in order to send pull requests. The problem is that my way to do was very ... dirty.

我处理了fork的本地副本,为我的修改创建了一个分支,并将其合并到master上.然后,我将主人推到github叉上,以创建请求请求.

I worked on a local copy of the fork, created a branch for my modifications and merge it on the master. Then I pushed the master on the github fork in order to create a pull request.

问题在于,最近,我的请求请求已被拒绝.所以现在我比原先的大师快了5承诺.为了与原始存储库保持一致,有什么解决方案?

The problem is that recently, my pull request have been rejected. So now I am 5 commits ahead from the original master. What are the solutions in order to be even with the original repository?

我是否必须在新分支中检出上游主服务器,并使用它来创建新主服务器(如何执行此操作?)

Should I have to checkout the upstream master in a new-branch and make the new master with it (how to do this?)

或者删除我的github分支(我已经接受了以前的提交)并重新创建(您可以在这里看到github仓库)还是更好的选择 https://github.com/cedlemo/ruby-gnome2

Or is it better to delete my github fork (I have previous accepted commits) and recreate it (you can see the github repos here)https://github.com/cedlemo/ruby-gnome2

推荐答案

首先,您应该始终将PR形成分支机构,而不是来自master.
master用于镜像upstream/master,其中"upstream"是您创建的原始存储库的名称.

First, you should always make your PR form a branch, not from master.
master is for mirroring upstream/master, with 'upstream' being the name of the original repo that you forked.

在您的情况下,请确保upstream存在,创建一个分支以引用您当前的补丁,然后将master重置为upstream/master:

In your case, make sure that upstream exists, make a branch in order to reference your current patches, and reset master to upstream/master:

之前:

  z--z (upstream/master, with new commits)
 /
z--y--y--y (master with local patches, origin/master)

记住当前的工作

git checkout master
git checkout -b mybranch
git remote add upstream /url/original/repo
git fetch upstream

# reset master to upstream/master
git checkout master
git reset --hard upstream/master
git push --force

  y--y--y (mybranch)
 /
z--z--z   (master, upstream/master, origin/master)

# replay the patches (even they are rejected for now) on top of master
git checkout mybranch
git rebase master
git push -u origin mybranch

        y'--y'--y' (mybranch, origin/mybranch)
       /
z--z--z   (master, upstream/master, origin/master)

此处:git reset --hard upstream/master将在已更新的upstream/master上重置master HEAD,以便主服务器反映与原始存储库中完全相同的历史记录.

Here: git reset --hard upstream/master will reset master HEAD on the updated upstream/master, in order for master to reflect the exact same history as the one in the original repo.

但是,由于某些提交以前是在master上完成的,并在派生(origin/master)上推送,因此您需要用新的master状态替换该历史记录.因此,git push --force.

But since some commits where previously done on master and pushed on the fork (origin/master), you would need to replace that history with the new master state. Hence the git push --force.

对mybranch进行重新设置使这些当前修补程序可以基于原始存储库的最新提交.

Rebasing mybranch allows for those current patches to be based on the most up-to-date commit of the original repo.

这篇关于github fork:你的分支是5承诺如何在不推送的情况下清理它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆