Remove/drop current commit within interactive rebase

544 views Asked by At

I'm in an interactive rebase and have marked the commits on which I need to have a closer look with edit (e) now while looking into the commits I realize that some of the commits need to be dropped/removed. Which is the correct commit to do that within the interactive mode?

Currently I perform the following commands:

$ git reset HEAD^
$ git checkout -- <File> # <- here I list all of the files that need to be reset
$ git rebase --continue # this complains that I have to perform git commit --allow-empty or git reset
# since I don't want the empty commit I do …
$ git reset
$ git rebase --continue

This is very lengthy. So I tried

$ git reset --hard HEAD^
$ git rebase --continue

But that produces a merge conflict.

So what is the easiest way to drop the current commit, when beeing in the edit mode of an interactive rebase?

2

There are 2 answers

0
Marco Luzzara On

If you git reset --hard you are also losing the changes of the current commit, hence the conflicts I suppose. Instead you could do a mixed reset with

git reset HEAD^

And amend the last commit with the changes in the current commit:

git add your_changes
git commit --amend -m "new commit message"
0
torek On

So what is the easiest way to drop the current commit, when beeing in the edit mode of an interactive rebase?

For me, the easiest way, by far, is to make a note of the commit I want to drop (subject line and any other identifying marks), finish the interactive rebase, and start a new interactive rebase and mark the commit as "drop". There is no need to do it all at once!