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

Git accidentally committed after checking out other commit

I left my main branch to checkout a specific commit and forgot to go back, resulting in my subsequent commits as being part of that checked-out commit rather than the main branch. Shown in git reflog

f0420e4 HEAD@{1}: commit: :brain: `redesign` attributes as single number -> Attribute object encapsulating .base .modifier
cb4a198 HEAD@{2}: commit: :brain: `redesign` Item Rarity type: string literals -> enum
1d61b75 HEAD@{3}: checkout: moving from main to 1d61b75
70c9cf5 (HEAD -> main, origin/main) HEAD@{4}: reset: moving to 70c9cf5ab06b1838b1b7c4b8278728bedbaecbf5

in main, I don’t see the most recent two redesign commits – they seem to be only existing on the 1d61b75 commit. How can I move them to be on the main branch, without having a merge register in my git history?

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 :

Go back to main and do a cherry-pick for the commits you need:

$ git checkout main
$ git cherry-pick cb4a198 f0420e4

Naturally, there can be conflicts, but if so, just fix them and do git cherry-pick --continue.

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