Home > other >  rebase a commit without merging it into the base commit (just move it next to a specific commit on a
rebase a commit without merging it into the base commit (just move it next to a specific commit on a

Time:10-23

i had a main branch that looked like this at some point in the history.

A <-- B <-- C <-- D  (main)

at this time i squashed C into the D using interactive rebase and got commit C'. on commit C' i created v1 branch and while i was on main branch i made another commit (E). so the repository now looks like this:

A <-- B <-- C' <-- E (main)
           (v1)

again i squashed C' into E and got C".

A <-- B <-- C'(v1)
      ⇡__ C"(main)

after that i made another commit F and Squashed C" into it and got C"'. so at the current time my repository looks like this:

A <-- B <-- C'(v1)
      ⇡__ C"'(main)

now i want to rebase commit C"' on top of C' but without having to merge their differences from their common parent B. in other words i want to move C"' on top of C' as if i directly made all the changes to C' and after committing those changes i got C"'

CodePudding user response:

Sounds like you want to:

git checkout main # check out branch main (commit C''')
git reset --soft v1 # move HEAD to v1 (commit C'), but keep all files and keep index
git commit -C "C'''" # commit index with commit message of commit C''' (previous tip of "main")
  • Related