将提交从一个分支移动到另一个分支

发布于 2024-10-01 06:00:54 字数 553 浏览 2 评论 0原文

我已经在我的 git 存储库的 master 分支上提交了一系列更改,并将其推送到上游(尽管我是唯一一个在这些更改中工作的人。)我想要做的是取消最后几次提交,滚动将 master 恢复到拉取提交之前,将提交重新应用到开发分支,然后合并回 master。

这是我的存储库现在的样子:

a [master] [remotes/origin/master]
|
b
|
c
|
d (merge branch 'develop')
|\
| \
|  e [develop] [remotes/origin/develop]
|  |
q  f
|  |
r  g

这就是我希望它的样子:

Z [master] [remotes/origin/master]
|\
| \
|  A
|  |
|  B
|  |
d  C
|\ |
| \|
|  e [develop] [remotes/origin/develop]
|  |
q  f
|  |
r  g

我可以得到一些帮助吗?我认为这是一项 rebase 工作,但我不太确定如何实现它。

I've committed a bunch of changes onto the master branch of my git repository, and pushed it upstream (although I'm the only one working out of these.) What I want to do is to pull these last few commits off, roll back master to before the pulled-off commits, re-apply the commits onto the develop branch, and then merge back onto master.

Here's what my repository looks like now:

a [master] [remotes/origin/master]
|
b
|
c
|
d (merge branch 'develop')
|\
| \
|  e [develop] [remotes/origin/develop]
|  |
q  f
|  |
r  g

And here's what I want it to look like:

Z [master] [remotes/origin/master]
|\
| \
|  A
|  |
|  B
|  |
d  C
|\ |
| \|
|  e [develop] [remotes/origin/develop]
|  |
q  f
|  |
r  g

Can I get some help on this? I'm thinking this is a job for rebase, but I'm not quite sure how to make it happen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻梦旅人 2024-10-08 06:00:54

在这里:

# move cba onto e
git branch foo
git rebase --onto <SHA1-e> <SHA1-d> foo

# rewind master to d
git checkout master
git reset --hard <SHA1-d>

# merge
git merge foo

您可能想要选择一个比 foo 更具描述性的分支名称,因为它将记录在 Z 的合并提交消息中。

Here you are:

# move cba onto e
git branch foo
git rebase --onto <SHA1-e> <SHA1-d> foo

# rewind master to d
git checkout master
git reset --hard <SHA1-d>

# merge
git merge foo

You might want to pick a more descriptive branch name than foo, since it'll be recorded in the merge commit message for Z.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文