在 git 中回滚或重新创建 master 分支?
我有一个 git 存储库,它有几个分支 - 有主分支,这是我们稳定的工作版本,然后有一个开发/暂存分支,我们正在其中进行新工作。
不幸的是,似乎我没有想到对变基有点过于热心,并在一段时间内将所有暂存代码拉入 Master(大约 80 次提交……是的,我知道,愚蠢、笨拙、糟糕的代码管理等等……)。
因此,我很难对当前版本的应用程序(Rails 应用程序)进行小修复并推出更改,而不推出我们还不想发布的“分阶段”新功能。
我想知道是否可以执行以下操作:
- 确定最后一个“主干”提交
- 获取从该点开始的所有提交并将它们移动到单独的分支中,或多或少回滚更改
- 开始使用分支,就像它们的用途一样。
但不幸的是,我仍在不断学习 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:
- Determine the last 'trunk' commit
- Take all commits from that point onward and move them into a separate branch, more or less rolling back the changes
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将会出现发布问题(这意味着您必须:
)
如果您的情况是:
也就是说,如果您当前的 master 实际上也是当前的 stage 分支,则需要进行简单的重置(正如 knittl 在 他的答案)
但是如果你的情况是:
如:“我已将 stage 集成到 master 中,然后继续为主人工作!”
,然后rebase - -onto 是有序的:
你将得到:
There will be the issue of publication (meaning you will have to:
)
if your situation is:
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:
as in: "I have integrated stage into master, and then go on working on master!"
, then a rebase --onto is in order:
you will get:
您是否已将提交推送到远程存储库?如果没有,您可以简单地使用
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)