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
a-b-c
\-d
How can I accomplish this?
>Solution :
The easiest way:
- Remember the
d‘s SHA1, let say it is535dce28f1c68e8af9d22bc653aca426fb7825d8. git reset --hard HEAD~2git cherry-pick 535dce28f1c68e8af9d22bc653aca426fb7825d8
More advanced:
git rebase -i HEAD~3- Change the second
picktodrop, or remove that line, then save the file and exit from the editor.
More advanced 2:
git revert HEAD~1will makeb-c-d-^cgit reset --soft HEAD~3will reset toband keep the changes on the diskgit add -A && git commitwill makeb-d'.