编辑旧提交与 git 非交互方式



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

$ 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

我怎样才能自动接受什么 git 变基 --交互式呈现给我?

这是

"git filter-branch"和选项"--commit-filter"的工作。查看手册页这里存在一个示例部分。

您可以在没有交互式变基的情况下做同样的事情:

git branch some_temporary_name # to save your initial place
git reset --hard commit_you_want_to_change
...edit...
git commit --amend -m 'some message'
git rebase your_initial_branch_name some_temporary_name
git checkout your_initial_branch_name
git merge some_temporary_name # This will be a ff since you rebased
git branch -d some_temporary_name # remove unneeded branch

最新更新