Remove commits from git rebased branch after other commits have been made
I have a project with two branches called master and function / x . In function / x I am working on new functions to be merged with wizard.
For an error in function / x , a master based swap action was executed and clicked. In addition, other commits were made and the / x function was pushed .
So, I have two branches that contain the "same commits" marked with different hashes.
A -- B -- C -- D [master]
\
E -- F -- G -- H -- I [feature/x]
where C
and D
on master , respectively, commit (reset) F
and G
into function / x .
I would like to remove F
and G
from the / x function while maintaining H
and I
. How can i do this?
I'm going to return commit
git revert F G
from feature / x , but these useless (duplicate) commits will remain in history. I would know if there is a better way to do this?
source to share
The easiest way is to repackage interactively: checkout feature/x
and do
git rebase -i E
then just remove the lines for F, G from the rebase script, you will be prompted to change. This will leave your branches looking like
master -> A -- B -- C -- D
\
feaure/x -> E -- H' -- I'
\
(orphaned) F -- G -- H -- I
You can do the same with
git rebase --onto E G feature/x
but the interactive method is much easier to remember (I had to look up the order of the arguments in the online help).
Note that old commits still exist and can be recovered, but will eventually be garbage collected if nothing happens to them.
source to share