5

I had something that looks like this

 6---7 (currentBranch) / 3---4---5---8 (initialBranch) / 1---2 (master) 

I squash merged initialBranch into master, so now master looks something like

1---2---9 where commit '9' is commits 3+4+5+8 squashed together 

My ultimate goal is to rebase currentBranch in the remote repo to look something like

 6---7 (currentBranch) / 1---2---9 

What are the series of commands I need to run to accomplish this?

5
  • 1
    You can use git checkuot currentBranch; git rebase -i 9 and drop all commits that were both squashed and remain parent of the commit #6 from the TODO list (#3, #4, #5): the TODO file will contain something like "pick 6 \n pick 7". This should work and may result in a conflict if the commit #8 brings something that cannot be automatically merged. Commented Nov 12, 2021 at 21:17
  • 1
    Or, if I'm not mistaken, git checkout currentBranch; git rebase --onto 9 7~2 currentBranch (but I'm not sure if it works as expected). Commented Nov 12, 2021 at 21:19
  • What have you tried so far? Commented Nov 12, 2021 at 21:25
  • To be honest, I have not tried much so far (in this instance). My experiences trying to rebase onto squashed commits in the past have resulted in what look like duplicates of all new changes, where PR file differences show existing changes as new even though master already has said changes (as part of the squashed commit). Trying to avoid messing things up and hitting that situation again Commented Nov 12, 2021 at 21:31
  • @fluffy I tried your first comment and it looks like that was everything I was looking for (aside from force pushing the changes into the remote repo). Thank you very much. If you submit an answer, I'll accept it as the solution here Commented Nov 12, 2021 at 21:49

2 Answers 2

2

If you still have the commit "merge base" between the original initialBranch and currentBranch, meaning commit 5, you can do a rebase --onto:

git rebase --onto master 5 currentBranch 

That would replay any commit after 5 (so 6 and 7) on top of the current master.

Sign up to request clarification or add additional context in comments.

Comments

0

If you still have the "initialBranch" you can avoid looking for commits references by:

git rebase --onto master initialBranch currentBranch 

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.