我想非交互式从我的历史记录中移除包含主题关键字的unpushed提交(类似于包含关键字的行被移除的交互式转化)。git非交互式地删除提交
以下nocommit在〜/ .gitconfig中的函数实现了我想要的功能,只是创建了一个新的结果分支。
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"
也应该可以用git push hook做到这一点,但我们已经有了三个挂钩,我不想修改。
编辑:使用此命令(由安德鲁·C中的答案启发)解决:
GIT_EDITOR="sed -i '/NOCOMMIT/d'" git rebase -i @{upstream}
可能重复[使用git filter-branch删除提交消息提交](http://stackoverflow.com/questions/4558162/using-git-filter-branch-to-remove-commits-by-their -commit-message) – Jubobs 2014-09-20 16:30:15
恐怕这不能保证是非交互式的。无论何时从历史记录中删除提交,都有发生冲突的风险,并且必须以交互方式解决。 – 2014-09-21 07:00:34