I have a new line of work that I want to become master. It has diverged from master too much to merge or rebase (though I've manually ported the functionality). I realize I can easily do a git branch -D master; git checkout new-master; git checkout -b master
git branch -D master; git checkout new-master; git checkout -b master
git branch -D master; git checkout new-master; git checkout -b master
, but I don't want to screw up any forks.
Ideally, I'd like to introduce a commit that turns the current master into a state where I can apply my changes from my new branch, so that anyone with a fork can just git pull origin master
and git things without incident.
Is this possible?
If you just want branch master
to refer to a new commit whose contents are identical to branch branch
, with the delta between master^
and master
being "change everything to match the contents of branch branch
", that's pretty easy:
$ git checkout branch
$ git symbolic-ref HEAD refs/heads/master
$ git status # you'll see what you're about to commit, here
$ git commit # make that new commit
Note that the branch history for master
will not refer to branch
here.
If you want the commit to look like a merge that changes everything to the way branch
looks, this seems to do the trick, but I have not tested it well:
$ git checkout master
$ git merge --no-commit -s ours branch # this sets up the merge
$ git rm -r . # this empties it out
$ git checkout branch -- . # this adds everything from branch
$ git status # again, just to see what you're about to commit
$ git commit # and maybe edit the message to note that you took "branch"
Now master^
is what master used to look like and master^2
is the tip of branch
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.