Git branch a few commits back?

Here's the current branch setting:

A---B---C-----------------D---E---F master
         \
          G---H---I---J---K---L branchA

I realized that when I went to work on branchA, the last few commits were for a new function, which should be a new branch. So I want it to look like this:

A---B---C-----------------D---E---F master
         \
          G---H---I------------M branchA
                   \
                    J---K---L branchB

I do not want to rename the branch, as that would rename G, H and I to the new branch name. I can create a new branch starting with i ( git branch branchB <SHA-of-I>), but what is the best way to “move” J, K, and L commits? git merge branchA, while on branch B it simply quickly moves the head of the branch to the same point as branch A.

+3
source share
3 answers

You do not need to move J, K and L. Do you want them on branch B? Make branch point B to fix L.

git branch branchB branchA    # start branch B at commit L
git checkout branchA
git reset --hard <SHA1-of-I>

# If you don't want to check out branchA, you could use
#     git branch -f branchA <SHA1-of-I>

, , - , , I.

commit M , rebase. branchA git rebase --onto <SHA1-of-I> <SHA1-of-L> branchA, commit L branchA commit I.

+6
0

G, H, branchB branchA. , branchA branchB I, branchA, commit M - branchA, , .

As far as I know, branches are simply called headers pointing to specific commits (see .git / refs / heads), and the rest of the tree is determined solely by parent-child relationships in git. Even if you manage to reinstall JKL on a new branch B and transfer M to now free space, the object data will be identical. Both M and J will point to me as their parents, and G / D will point to C as their parents, and the rest will simply point to their immediate parent. Did I miss something?

0
source

Source: https://habr.com/ru/post/1773305/


All Articles