【问题标题】:In git how do I delete/drop a specific commit from history (rebase) programmatially?在 git 中,我如何以编程方式从历史记录(变基)中删除/删除特定提交?
【发布时间】:2020-03-03 08:25:42
【问题描述】:

我知道如何以交互方式修改 git 历史记录和 drop 特定提交,但我没有找到完全自动完成此操作的方法。

我想识别特定的提交(例如,包含一个魔术字符串)并让它们被脚本删除。

类似这样的:

# identify and remove all commits which would be merged to master but should not
for i in $(git --no-pager log --grep='no-push' --pretty=format:"%h" --no-merges HEAD ^master)
do
    echo "Drop commit $i"
    git rebase --drop $i   # <== this is what I want to do
done

有什么想法吗?

【问题讨论】:

标签: bash git shell git-rebase


【解决方案1】:

取自here(感谢jonrsharpe):

# identify and remove all commits which would be merged to master but should not
for i in $(git --no-pager log --grep='no-push' --pretty=format:"%h" --no-merges HEAD ^master)
do
    echo "Drop commit $i"
    git rebase -p --onto $i^ $i
done

【讨论】:

  • 完全正确和有用 - 在这种情况下,我知道我只得到没有任何空格的 git shas。但请随时改进代码
猜你喜欢
  • 2014-05-05
  • 2014-11-20
  • 2013-08-03
  • 1970-01-01
  • 2015-09-02
  • 2013-09-20
  • 1970-01-01
  • 2012-04-06
  • 2012-04-04
相关资源
最近更新 更多