I have a local and its corresponding github repo. I have some commits as
A <- B <- C <- D
A being the latest.
This is situation on both the repos. I want to delete commit C as if it never happened.
So it should be like on git log
A <- B <- D
on both repos.
I tried git reset --soft <sha-commit-C>
and am now stuck. I can not see A, B
. Before doing any further steps i want to be fully sure that i know what i am doing.
git reflog
gives me :
git reflog
73ea54d HEAD@{0}: reset: moving to 73ea54d8
a594699 HEAD@{1}: rebase -i (finish): returning to refs/heads/unique_ptr_release
a594699 HEAD@{2}: checkout: moving from unique_ptr_release to a594699fb6f7d85bc8
a594699 HEAD@{3}: checkout: moving from unique_ptr_release to unique_ptr_release
a594699 HEAD@{4}: commit (merge): Merge branch 'master' into unique_ptr_release
HEAD@{4}
is what my Head was before reset --soft
command.
How do i get out of this situation ?
Git-rebase is what are you looking for.
in your case of commit A-B-C-D
, and want to remove C, try:
git rebase -i HEAD~3
it will show the last 3 of your commits via editor (mine is vim),
just delete (in vim: dd
) the line of commit you want to remove,
then save it (in vim: :wq
).
Done, view the git log
and you will see that the C
commit is removed.
*don't forget to backup your code or .git folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With