Change past commit from a previously merged branch, keeping the branch history

Problem

Say that I have done some work on master:

c1 <- c2
       ^
     master

At this point, I disconnect and do another job:

                test                  
                 v
          c3 <- c4
c1 <- c2 /
       ^   
     master

Then do a git merge --no-ff( --no-ffto save the branch history):

                test                  
                 v
          c3 <- c4
c1 <- c2 /        \ [c5]
                      ^   
                    master

( [c5]is a merge commit)

Then I delete the branch test, thinking that I am done with it. However, I believe that, in the end, there is a problem with the work that I did on test. I need to change c3, but without harming the history of the branches.


Things i tried


My attempt

I git checkout c3; , , git commit --amend. checkout master git branch temp c3. git rebase --preserve-merges temp: , , git add <file> git rebase --continue.

, git log --oneline --graph, - :

*  [c5]
|\
| * c4
|/
* c3'
* c2
* c1

:

*  [c5]
|\
| * c4
| * c3'
|/
* c2
* c1

c3' - .

git?

git checkout c3
git checkout -b test
git commit --amend
git checkout master
git reset --hard c2
git merge --no-ff test

, , c4. (, , , .) git log --oneline --graph :

*  [c5]
|\  
| * c3'
|/  
* c2
* c1

[c5'] - . ( , , .)

+4
3

, ! , , --interactive rebase.

, git rebase -p -i <root>; , <root>. <root> c2.

-p --preserve-merges, git rebase .

:

pick c3 <message>
pick c4 <message>
pick [c5] <message>

pick c3 edit, :

edit c3 <message>
pick c4 <message>
pick [c5] <message>

. , , git commit --amend. git rebase --continue rebase.

. , git add , , git rebase --continue. , git , .

+1

rebase:

git checkout master
git rebase -i c2

. pick c3 edit. . git c3 . ,

git commit --amend
git rebase --continue
+1

, c4 commit , c4, , - no-ff ?

About what you tried. It seems that you made changes to the timeline of the timeline of the master branches, so the fixation schedule is an obvious consequence.

0
source

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


All Articles