Git rebasing上游 [英] Git rebasing to upstream

查看:91
本文介绍了Git rebasing上游的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我分出了一个项目,并做了一些修改,并将它们推送给origin / master。这些变化我并不打算送回上游。我一直在寻找并且很好,直到现在我有一些变化,我想推上游。



我可以在不同的分支重新回到上游,并提交给那个分支吗?我可以从我的分支提交这些更改吗?我是否可怕地损坏了我的回购?

不,不要捣乱。只需从上游/主机分支,在那里进行提交,然后就可以推送(或拉取请求)那些与上游/主机完美匹配的提交。

如果你有A --- B --- C,其中上游/主人在A,主人在C,这意味着B和C是你不想向上游发送的提交,那么:

  git checkout -b发送上传A 
#工作,工作,工作
#提交
git log A. .HEAD#这将是提交上行的提交

如果你有提交,你不打算发回给主人,如果你将这些东西移动到不同的分支并让主人与上游/主人保持同步,跟踪事情可能会更简单:

  git分支my-stuff-not-sent-upstream 
git reset --hard A#将消除本地更改!
git push origin master -f#如果共享的远程机器可以丢失历史!
git push origin my-stuff-not-sent-upstream

将有效地取代master withmy-stuff-not-sent-upstream,并将master和origin / master设置为与上游/ master相同的提交。


So I forked a project, and made a few changes and pushed those to origin/master. These changes I didn't intend to send back to upstream. All is find and good until now I have some changes I do want to push upstream.

Can I rebase back to upstream in a different branch, and commit to that branch? Can I commit these changes from my branch? Have I horribly mangled my repo?

解决方案

No, no mangling. Just branch from upstream/master, make your commits there, and then you can push (or pull-request) those commits, which fit neatly onto upstream/master.

If you have A---B---C, where upstream/master is at A and master is at C, meaning B and C are commits you don't want to send upstream, then:

git checkout -b to-send-upstream A
# work, work, work
# commits
git log A..HEAD # this will be the commits to send upstream

If you have commits you're not going to send back on master, it might be simpler to keep track of things if you move those into a different branch and keep your master in sync with upstream/master:

git branch my-stuff-not-sent-upstream
git reset --hard A # will wipe out local changes!
git push origin master -f # can lose history if a shared remote!
git push origin my-stuff-not-sent-upstream

will effectively replace "master" with "my-stuff-not-sent-upstream" and set master and origin/master back to the same commit as upstream/master.

这篇关于Git rebasing上游的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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