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

Revert HEAD{2} from a branch without reverting HEAD{1}

I am trying to contribute to a GitHub repository. The commit from before I started contributing I’ll call "a". I made a commit "b" and my pull request for it was accepted. I then made another commit "c" and I have made a pull request for it but it has not yet been accepted. I made another commit "d" which I committed to a new branch so I’d be able to pull it separately. However, I forgot to rebase back to "b" before creating "d" so the branch for "d" also contains "c" meaning "c" would exist on both branches which I don’t want.

So, currently I have this

a-b-c-d

But I want this

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

a-b-c
  \-d

How can I accomplish this?

>Solution :

The easiest way:

  1. Remember the d‘s SHA1, let say it is 535dce28f1c68e8af9d22bc653aca426fb7825d8.
  2. git reset --hard HEAD~2
  3. git cherry-pick 535dce28f1c68e8af9d22bc653aca426fb7825d8

More advanced:

  1. git rebase -i HEAD~3
  2. Change the second pick to drop, or remove that line, then save the file and exit from the editor.

More advanced 2:

  1. git revert HEAD~1 will make b-c-d-^c
  2. git reset --soft HEAD~3 will reset to b and keep the changes on the disk
  3. git add -A && git commit will make b-d'.
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