我知道如何手动编辑旧提交:
$ 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?
答案 0 :(得分:2)
这是“git filter-branch”和“--commit-filter”选项的作业。查看手册页面这里有一个示例部分。
答案 1 :(得分:1)
如果没有交互式rebase,你可以做同样的事情:
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