Git: working on a merged branch that was not thereafter

I have the following problem: I worked in branch A. Branch A was merged with the branch of the master, so beautiful.

After some time, the customer decided to cancel the changes made in Branch A on the Master branch, because it needs to be updated.

So, the story in the wizard branch looks like this:

Some stuff
Some other stuff
Some stuff, where the merge of Branch A was reverted
Some other stuff
Some other stuff
Branch A was merged into master
The commit of Branch A (Branch A contains one Commit)

I want to reinstall Branch A, so I need something like:

The commit of Branch A (From here I want to continue working)
Some stuff
Some other stuff
Some stuff, where the merge of Branch A was reverted
Some other stuff
Some other stuff
Branch A was merged into master
The commit of Branch A (Branch A contains one Commit)

Please note that I do not want to change the history of my remote master, I need to commit the branch A to be reformatted at the last commits of my master. Then I want to push my updated branch A back to the Master again.

Now I want to continue working on Branch A, but first I want to reinstall Branch A on the current main branch in order to have the newest state.

, : A master, git, , , Branch A. , . : git , A , , A master, .

, Branch A Branch, checkout . , , ?

+4
3

git checkout branch-a && git rebase -i master, pick . , . , skip , .

, git revert , branch-a.

+1

, . HEAD BranchA master, git , , BranchA. , , , reset , .

, - .

, rebase --onto, , .

git rebase --onto <commit_id_before_merge_commit> <revert_merge_commit_id> master

-, BranchA, git , master.

git checkout BranchA
git reset HEAD^n # n is the number of commits that are exclusive to branchA
git add -u # Add all the files. Make sure to add newly created ones.
git commit -m 'some message'
git rebase master # should work now

-, BranchA

git rebase -i <first_exclusive_initial_commit_id_of_branchA>
+1

, , , . , <revert>, :

  • <revert> , , , ( --x == x).

  • , :

    • Create a patch sequence for your branch with git format-patch.

    • Apply this patch sequence to manage with git am.

    The fact is that he git amis an agnostic of history: he looks only at the current state of fixation and applies patches to it.

0
source

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


All Articles