I prepare a repo for publication and need to fully remove certain internal information from its history. This data can be in various files which I have to check/prune manually. Note that not the whole file should be deleted, just certain content.
When I do git rebase -i --root
I can mark all commits that (a) potentially need modification as edit
and those that (b) need to go completely as drop
. (Note: The list of commits to review is not too long and was optained by using git log --stat | grep 'commit\|name1\|name2\|...'
.) While screening the commits of type (a) I might find one that actually needs to be dropped completely. For this I tried rebase --skip
but, to my surprise, that still leaves the commit in place.
How can I remove a commit during git rebase
which I selected to edit
initially?
Example:
$ git init
$ for COM in A B C; do touch $COM; git add $COM; git commit -m "add $COM"; done
$ git rebase -i --root
<mark all as 'edit'>
<modify file and change commit>
$ echo A > A; git add A; git rebase --continue
<commit needs to go away>
$ git rebase --skip
<modify file and change commit>
$ echo C > C; git add C; git rebase --continue
File B
still exists after this.
Instead of git rebase --skip
, use
git reset --hard HEAD^
git rebase --continue
The git reset
will remove the commit.
git rebase --skip
doesn't remove the commit that's already been applied at that point.