Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to rebase diverged Git branches in chronological order?

I was working on my dev branch, then made some commits (A, B, C). I switched to the main branch for some reason at this point, did edits on different parts of the same files I worked on before (the reason why I didn’t notice that I’m on a different branch), then commited D

* (4th) D (HEAD -> main)
|
|  * (3rd) C (dev)
|  * (2nd) B
|  * (1st) A
| /
|/
* x
* y
* z

What is the most straightforward way to have A, B, C, and D on one branch (doesn’t matter if it’s main or ‘dev`) in the same order they have been created?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

From main you can just run git rebase dev. That will replay everything you have in main which isn’t also in dev (just D according to your diagram) onto the tip of dev.

Your main branch will then be in the state you want and your dev branch will be unchanged.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading