I would like to non-interactively remove unpushed commits containing a subject keyword from my history (similar to interactive rebase where the lines containing the keyword is removed).
The following nocommit function in ~/.gitconfig achieves almost what I want, except that a new resulting branch is created.
nocommit = "!f() { \
for i in `git log --oneline FETCH_HEAD.. |grep NOCOMMIT | awk '{ print $1 }'`; \
do \
git log -n1 --oneline $i; \
git rebase --onto $i^ $i HEAD; \
done; \
}; f"
It should also be possible to do this with a git push hook, but we already have in-three hooks in that I don't want to modify.
Edit: Solved with this command (Inspired by the answer from Andrew C):
GIT_EDITOR="sed -i '/NOCOMMIT/d'" git rebase -i @{upstream}