Most of the time if you want to drop some commit, you can use git rebase -i
to drop the commit. But it is hard to using when we want to write a script to drop some commit. Because it need to select the commit to drop interactively.
So if you want to drop one commit (or some continuous commits) in a script, you can use git rebase --onto
. For example, if you want to drop the commit with message your commit message
, you can use the following command:
sh
$(git log --format="%H" -1 --grep="your commit message")
commit=if [ -n "$commit" ]; then
$(git rev-parse "$commit"^)
parent_commit="$parent_commit" "$commit"
git rebase --onto fi