Move a branch to another point in the story

We have the following story

start         master  public
|                 |   |
v                 v   v
o---o-- ... --o---o---o

Unfortunately, we have committed some commits to a branch mastercontaining some sensitive data. We changed this in a separate branch called public. Now we want to “disconnect” the branch publicto get a complete and clean “state” in public, but without the compromising parts of the story still contained through master. In other words, we need the following new story:

start         master
|                 |
v                 v
o---o-- ... --o---o
 \
  o <- public

Now the check publicwill lead to the same working tree as in the initial situation, but without detailed history information. Subsequently, we will cancel the old branch master: rename it to unsafeand develop a new branch masterfrom the new branch public. Thus, we keep the old story in unsafeand can insert the branch publicinto the public without any worries:

start         unsafe
|                 |
v                 v
o---o-- ... --o---o
 \
  o---o-- ... --o <-- public
   \           /
    o-- .. --o-- ... --o <-- master

What are the proper git commands to achieve this?

PS: Of course, we can check start, create a new branch and fix the whole tree of the branch work there public. But there must be a different, more convenient, git way!

+5
source share
1 answer

(.. ..) git rebase -i. , (, start, ):

git checkout public
git rebase -i start

, squash . , , git . , - .

, :

git checkout -b unsafe master # <- creates a new branch "unsafe"
git checkout master
git reset --hard public    # <- forces master branch to point to public

unsafe, reset , () . , .

master unsafe, :

git branch -m master unsafe  # renames master to unsafe
git checkout -b master public  # creates new branch master as a copy of public

. (, ...)

+3

All Articles