Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change root of a branch in git

I'm using git and want to change the base of an exiting branch. This is caused by a deployment system, which pulls this explicit branch into my production environment. When planning my releases, I create a tag every time I want to go live. But my branch has special changes too, so git reset --hard v1.0 won't work.

Here a small example. I want this

      C---D---E deploy
     /
A---B---F---G master
     \
      v1.0

to become this

                          C---D---E deploy
                         /
A---B---F---G---H---I---J---K master
     \                   \
      v1.0                v1.1

Maybe git rebase is what I am looking for, but the man pages don't help me. Thanks for your replies!

like image 265
micha149 Avatar asked Apr 19 '11 05:04

micha149


1 Answers

git rebase should, like you say, allow you to change the base of deploy:

git checkout deploy
git rebase v1.1 # using the tag
(or:
 git rebase J # SHA1 of J
 or
 git rebase master~1
)

But you will end up with

C'---D'---E' deploy

That is, the SHA1 of the commits part of deploy branch are rewritten, which isn't too bad if nobody cloned said deploy branch and was working on it.
Since it is a branch for deployment, that is most likely the case (i.e. nobody was working on a clone of said branch).

like image 87
VonC Avatar answered Sep 23 '22 06:09

VonC