Git: removing changes made by a number of bad commits

Let's say I have a git repo with such a commit history: ABCDE

Now, all of a sudden, I realize that commits B and C are completely erroneous and unnecessary. Also, let's say I have complete freedom to rewrite the history of the project (perhaps I am working on the project alone).

I have another branch pointing to commits B and C, so losing them is not a problem. If I really need these changes, I can check this thread and see them.

But for the main branch, I would like to make the story be A-D'-E ', where D and E not only have a list of changed parents, but also do not contain the changes that were introduced by commits B and C.

Can this be done? And if so, how?

+3
source share
3 answers

git rebase -i HEAD~5

Then remove unnecessary commits from the commits list

+5
source

I am going to assume that there are 5 commits.

In this case, you will do:

git rebase -i HEAD~5

Then you remove 2 lines related to commits B and C.

Finally, you will do a:

git rebase --continue
+2
source
git rebase --onto $commit_A $commit_C $commit_E

: " C, E E, A".

, , . . master E, , C, backup, :

git rebase --onto $commit_A backup master

, HEAD, master, master, , E.

+1

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


All Articles