Please, before closing as duplicated question, take in account I am trying to follow some recommendations found around.
I have two branches and I don't want to create a new branch at all: master and develop in my company. I don't want to revert because it will keep the history as far as I understand (git reset --soft mylast-good-commit). I really don't want to touch on master. Lets say my last two commits in develop I did something very ugly and I would like to delete them completetely from github.
My last commit: 50021514 (I want to delete from github including the history)
My second last commit: 0b63ca64 (I want to delete from github including the history)
My third commit: 571ebdfa (I want this to be the head from now on)
Tentatives:
1)
C:\dev\my-app>git rebase -p --onto 571ebdfa
result in
pick 0b63ca6 bower dependency versions reseted to fd042953
pick 4cce2c4 revert "bower dependency versions reseted"
# Rebase 571ebdf..4cce2c4 onto 571ebdf (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
then I typed :wq and I got
interactive rebase in progress; onto 571ebdf
Last command done (1 command done):
pick 0b63ca6 bower dependency versions reseted to fd042953
Next command to do (1 remaining command):
pick 4cce2c4 revert "bower dependency versions reseted"
You are currently rebasing branch 'MyBranch' on '571ebdf'.
nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
If you wish to skip this commit, use:
git reset
Then "git cherry-pick --continue" will resume cherry-picking
the remaining commits.
Could not apply 0b63ca6... bower dependency versions reseted to fd042953
But I still see all alst two commits in github. Am I missing some extra step here or did I understand wrong that it is possible to use "rebase -p onto" to reach what I want?
2) git rebase -i 571ebdfa
pick 0b63ca6 bower dependency versions reseted to fd042953
pick 4cce2c4 revert "bower dependency versions reseted"
# Rebase 571ebdf..4cce2c4 onto 571ebdf (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
/c/dev/my-app/.git/rebase-merge/git-rebase-todo [unix] (10:23 14/06/2018) 1,1 Top"C:/dev/my-app/.git/rebase-merge/git-rebase-todo" [unix] 21L, 755C
then I tried :wq
and I get
Last command done (1 command done):
pick 0b63ca6 bower dependency versions reseted to fd042953
Next command to do (1 remaining command):
pick 4cce2c4 revert "bower dependency versions reseted"
You are currently rebasing branch 'MyBranch' on '571ebdf'.
nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
If you wish to skip this commit, use:
git reset
Then "git cherry-pick --continue" will resume cherry-picking
the remaining commits.
Could not apply 0b63ca6... bower dependency versions reseted to fd042953
Isn't rebase aimed to be used in this case: when we want to return to a previous commit not only in our local but in our remote repository as well?
3) git revert 0b63ca64 50021514
This reverts commit 0b63ca6484cc9225c75b19ede27fe90e39e6d094.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch MyBranch
# Your branch is up to date with 'origin/MyBranch'.
#
# Last command done (1 command done):
# pick 0b63ca6 bower dependency versions reseted to fd042953
# Next command to do (1 remaining command):
# pick 4cce2c4 revert "bower dependency versions reseted"
# You are currently rebasing branch 'MyBranch' on '571ebdf'.
#
/c/dev/my-app/.git/COMMIT_EDITMSG [unix] (10:34 14/06/2018) 1,1 Top"C:/dev/my-app/.git/COMMIT_EDITMSG" [unix] 20L, 738C
then I typed :wq
and I get
[MyBranch 9276513] Revert "bower dependency versions reseted"
2 files changed, 2 insertions(+), 1 deletion(-)
error: commit 50021514f6484eecff50e088686ed6b2f2203d47 is a merge but no -m option was given.
fatal: revert failed
Well, from user perspective I just want to delete the last two commits from a specific branch deleting as well their history.