A change was applied to a large codebase, then a formatter was applied, touching nearly every file.
A --------- B
A single commit B
combining those two actions lead to a gigantic diff that is a pain to review, and also difficult to split up manually with an interactive rebase and picking out hunks. However, I could easily contrive an intermediate commit I
by checking out A
and running the code formatter on that.
A --------- B
\
\
-- I
Given that I just made the commit I
, how can I easily generate a commit B'
that ends up with the exact same tree content as B
?
A --------- B
\
\
-- I --- B' # (has exact same contents as B)
If I naively do
git checkout B
git rebase I
I end up with a ton of conflicts. I don't want to have to be clever at all, I just want to end up at the exact same directory as B
, with the assumption that the I..B
diff will be dramatically smaller than A..B
.
Ok, if you already have I and B, you can do this:
git checkout --detach B
git reset --soft I # move branch pointer (HEAD pointer, in this case) to I, set all differences in index ready to be committed
git commit -m "blah blah"
Now you can point whatever branch you want where you are if you like the results:
git branch -f blah
git checkout blah
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With