VIAGC
VIAGC

Reputation: 839

Re-basing onto a specific commit

I checked Git: How to rebase to a specific commit? but I couldn't understand, my problem is not similar

Edit:

I tried using:

git rebase -i x

Upvotes: 3

Views: 151

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522171

You can approach this one way by just making the z commit on top of the x and y commits:

# from your branch
git commit -m 'z commit'

Then, we can do an interactive rebase, reorder the commits, and squash. Type the following:

git rebase -i --root your_branch

This should bring up an editor window, showing your three commits from oldest to newest:

pick dj39fm2 message for commit x
pick m83mdk2 message for commit y
pick 3kme92w message for commit z

Now, reorder the commits such that z comes right after x, and then change the option for commit z to squash, to tell Git that you want to squash it down to the x commit:

pick dj39fm2 message for commit x
squash 3kme92w message for commit z
pick m83mdk2 message for commit y

Now save the file, exit the editor, and allow Git to start the rebase. Note that you might get some merge conflicts during the squash, or as the y commit reapplied to a new base.

Upvotes: 1

Related Questions