Question

My current branches look like:

     D  
    /
H--A--B--C  

I was trying to work out how to produce a new git branch which would make the new git repo to looks something like:

     D  
    /
H--A--B--C  
    \
     C  

Is this possible to do? I thought about using reset but that would mean changes from C would also be lost, so looking for an alternative.

Was it helpful?

Solution

OK so found a way to do this.

I created a new branch with A in it:

git branch new-branch <A sha1>

Then I used cherry pick to merge C with A in the new-branch:

git checkout new-branch
git cherry-pick <C sha1>

And that made the repo with the branches I needed.

OTHER TIPS

    C                     A--D  
   /                     /
  A*--D                 H--A--B--C  
 /                       \
H--A--B--C                A--C
    (1)                     (2)

Because (1) is an equivalent if (2) you can just git checkout <commit sha1 of A*> -b your-new-branch

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top