开发者

Rolling back or re-creating the master branch in git?

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开发者_StackOverflow中文版 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!


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)


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜