在 git 中回滚或重新创建 master 分支?

发布于 2024-08-30 00:24:48 字数 473 浏览 5 评论 0原文

我有一个 git 存储库,它有几个分支 - 有主分支,这是我们稳定的工作版本,然后有一个开发/暂存分支,我们正在其中进行新工作。

不幸的是,似乎我没有想到对变基有点过于热心,并在一段时间内将所有暂存代码拉入 Master(大约 80 次提交……是的,我知道,愚蠢、笨拙、糟糕的代码管理等等……)。

因此,我很难对当前版本的应用程序(Rails 应用程序)进行小修复并推出更改,而不推出我们还不想发布的“分阶段”新功能。

我想知道是否可以执行以下操作:

  1. 确定最后一个“主干”提交
  2. 获取从该点开始的所有提交并将它们移动到单独的分支中,或多或少回滚更改
  3. 开始使用分支,就像它们的用途一样。

但不幸的是,我仍在不断学习 git,所以我对在这里真正做什么有点困惑。

顺便说一句,提交已被推送到远程,但我不介意用 --force 重新推送,我是唯一推送远程的人。

谢谢!

I have a git repo which has a few branches - there's the master branch, which is our stable working version, and then there is a development/staging branch which we're doing new work in.

Unfortunately it would appear that without thinking I was a bit overzealous with rebasing and have pulled all of the staging code into Master over a period of time (about 80 commits... yes, I know, stupid, clumsy, poor code-man-ship etc....).

Due to this it makes it very hard for me to do minor fixes on the current version of our app (a rails application) and push out the changes without also pushing out the 'staged' new features which we don't yet want to release.

I am wondering if it is possible to do the following:

  1. Determine the last 'trunk' commit
  2. Take all commits from that point onward and move them into a separate branch, more or less rolling back the changes
  3. Start using the branches like they were made for.

Unfortunately, though, I'm still continually learning about git, so I'm a bit confused about what to really do here.

By the way, commits have been pushed to a remote, but I don't mind re-pushing with --force, I am the only one who pushes remote.

Thanks!

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

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

发布评论

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

评论(2

绿萝 2024-09-06 00:24:51

将会出现发布问题(这意味着您必须:

  • 强制将新的主控推送到您的远程)
  • 与已经从该远程拉取的任何人进行通信,以便他们将其主控重置到远程

如果您的情况是:

m1-m2-m3-m4-s1-s2-s3-s4 (master,stage)

也就是说,如果您当前的 master 实际上也是当前的 stage 分支,则需要进行简单的重置(正如 knittl 在 他的答案

但是如果你的情况是:

m1-m2-m3-m4-s1-s2-s3-s4-m5-m6 (master)
                       \
                        -s5-s6 (stage)

如:“我已将 stage 集成到 master 中,然后继续为主人工作!”
,然后rebase - -onto 是有序的:

git checkout master
git reset --HARD m4
git rebase --onto master s4 m6

你将得到:

m1-m2-m3-m4-m5'-m6' (master)
           \
            -s1-s2-s3-s4-s5-s6 (stage)

There will be the issue of publication (meaning you will have to:

  • force push the new master to your remote
  • communicate with anyone having already pulled from that remote in order for them to reset their master to the remote one
    )

if your situation is:

m1-m2-m3-m4-s1-s2-s3-s4 (master,stage)

that is, if your current master its actually also the current stage branch, a simple reset is in order (as knittl mentions in his answer)

But if your situation is:

m1-m2-m3-m4-s1-s2-s3-s4-m5-m6 (master)
                       \
                        -s5-s6 (stage)

as in: "I have integrated stage into master, and then go on working on master!"
, then a rebase --onto is in order:

git checkout master
git reset --HARD m4
git rebase --onto master s4 m6

you will get:

m1-m2-m3-m4-m5'-m6' (master)
           \
            -s1-s2-s3-s4-s5-s6 (stage)
飘然心甜 2024-09-06 00:24:51

您是否已将提交推送到远程存储库?如果没有,您可以简单地使用 git reset (请务必先阅读联机帮助页,重置可能会很危险且令人困惑)

have you already pushed your commit to a remote repository? if you haven't you can simply use git reset <commit> (make sure to read the manpage before, reset can be dangerous and confusing)

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