Git rebase already merged branch?

I created a function branch from the main branch. After that, [F1] is fixed from the function branch.

        [F1]            -- Feature Branch
       /
[M1]-[M2]               -- Master Branch

After this, the characteristic branch is merged into the leading branch, and there are two more commands [M3] and [M4] in the main branch.

        [F1]                   -- Feature Branch
       /    \
[M1]-[M2]-[F1]-[M3]-[M4]       -- Master Branch

Now I have added two more commits for the branch function.

        [F1]-[F2]-[F3]         -- Feature Branch
       /   \
[M1]-[M2]-[F1]-[M3]-[M4]       -- Master Branch

At this time, I must first reinstall the attribute branch to the master branch, so that the function branch has the changes [M3] and [M4], or I have to merge git directly.

Also, if I do git rebase first, will [F1] be committed in both branches:

                       [F1]-[F2]-[F3]       -- Feature Branch
                       /
[M1]-[M2]-[F1]-[M3]-[M4]                    -- Master Branch
+3
source share
3 answers

. . Rebasing , . , , .

, git , git, . , , "", .

, rebase, , , , "merge" rebase , .

, rebase, : , . , , , , , , . " " .

+2

, .

:

", git, [F1] "

F1- , rebase.

https://git-scm.com/docs/git-rebase

, (, , ), . , git ( A A , ):

      A---B---C topic
     /
D---E---A'---F master

:

               B'---C' topic
              /
D---E---A'---F master
0

, master master, - , , , , ,

, , , (git rebase -i) , ( , [M2]).

( ):

        [F1]-[F2]-[F3]         -- Feature Branch
       /   \
[M1]-[M2]-[F1]-[M3]-[M4]       -- Master Branch

, :

pick hash_f1 [F1]
pick hash_m3 [M3]
pick hash_m4 [M4]

, [F2] [F3], [F1] . , [F1], .

:

        [F1]-[F2]-[F3]         -- Feature Branch
       /
[M1]-[M2]-[M3]-[M4]            -- Master Branch

master M , feature F , [M2]. , :

git merge --no-ff feature

- , :

        [F1]-[F2]-[F3]         -- Feature Branch
       /             \
[M1]-[M2]-[M3]-[M4]-[F*]       -- Master Branch

, , , . , .

In addition, this process can be extended to any links, and not just to the function and main branch, so there are other cases where this may make more sense. In my opinion, a stable branch such as master should not usually rewrite its history, but each Git environment and workflow are different, so there are really no rules that cannot be rewritten.

0
source

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


All Articles