git - 使用 git 以非交互方式编辑旧提交

标签 git scripting rebase

我知道如何手动编辑旧提交:

$ git log --pretty=format:'%h %s'
    60e5ed9 Second commit
    0fbc8ed First commit
$ git rebase --interactive 0fbc8ed # Going back to 'First commit'
    # * $EDITOR gets fired up *
    # change 'pick 0fbc8ed' to 'edit 0fbc8ed'
$ echo 'Hello Kitteh!' > some_file
$ git add some_file
$ git commit --amend -m 'some message'
$ git rebase --continue # Go back

这里的问题:

git rebase --interactive 启动一个编辑器,这对于脚本编写来说有点糟糕。有没有办法克服这个问题,即直接将 edit 0fbc8ed 传递给 git rebase 命令?

我的尝试是愚蠢的,还是有更清晰的替代方法来做到这一点?

有一个类似的问题,但在我的例子中,我想将 pick 更改为 edit:

How can I automatically accept what git rebase --interactive presents to me?

最佳答案

这是“git filter-branch”和选项“--commit-filter”的工作。查看手册页,这里有一个示例部分。

关于git - 使用 git 以非交互方式编辑旧提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10301446/

相关文章:

git - Git 是否可以永久在同一个子分支上工作?

c# - 在服务器上执行 powershell .ps1 文件并查看结果 C# asp.net

c# - 对 C# 应用程序的简单、快速脚本支持

windows - Powershell 脚本中的 System.Object [] 显示错误

git - 使用恢复到上次 git pull --rebase state 之前的状态

git - Phabricator arc land 将无法工作,因为功能分支上有多个修订版

java - 在 Mac 中找不到 'JAVA_HOME' 环境变量

Mercurial Mercurial merge 默认

linux - Git pull 权限被拒绝 linux?

git - 在大型 DVCS rebase 操作期间,多人如何为解决冲突做出贡献?