You can try git rebase -i -p HEAD~2
where ~2 is the last two commits.
git log
--to list the commits.
commit 0a6c84980 (HEAD -> hotfix/1, origin/hotfix/1)
Author: Murilo <[email protected]>
Date: Thu Aug 12 14:16:03 2021 -0300
commit original
commit dedde93a7498e
Author: Murilo <[email protected]>
Date: Fri Aug 6 17:21:20 2021 -0300
Commit duplicado
I run the rebase command listing the last two commits.
git rebase -i -p HEAD~2
Will load the following information;
pick dedde93a commit original
pick 0a6c8498 Commit duplicado
# Rebase 72337dee..0a6c8498 onto 72337dee (4 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <commit> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
Mark duplicate commit as "drop"
pick dedde93a original commit
drop 0a6c8498 Duplicate commit
# Rebase 72337dee..0a6c8498 onto 72337dee (4 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <commit> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
I give an Esc and type :x to save and problem solved.
It will run rebasing and then just push -f on the remote branch to force updates.
I usually use git to rebase -i <commit previous to what you want to delete> to change the history of a repository. It’s a Swiss Army knife that’s worth learning, because it’s meant to erase a commit from the story, change the order of commits, edit a commit in the middle, and so on.
– epx