如何以非交互方式运行 git rebase --interactive? [英] How do I run git rebase --interactive in non-interactive manner?
问题描述
是否可以进行以下操作?
Is it possible to do following?
- 使
git rebase --interactive
只是将标准样板输出到文件,而不是输出到文件并在编辑器中打开它. - 让用户编辑文件.
- 让用户重新运行
git rebase
并使用编辑后的文件名. - 继续执行通常的变基过程.
- Make
git rebase --interactive
to just output standard boilerplate to a file, instead to outputting to a file and opening it in editor. - Let the user edit the file.
- Let user re-run
git rebase
with the name of edited file. - Go on with the usual rebase process.
用例:当然是脚本化的变基.请参阅如何在 Git 中以非交互方式重新排序提交 例如.
Usecase: scripted rebasing of course. See how to re-order commits in Git non-interactively for example.
推荐答案
经过一番思考和研究,答案很简单:git rebase -i
从井中取编辑器名称-已知的 EDITOR/VISUAL 环境变量,因此覆盖它以指向非交互式脚本可以完成这项工作.
After some thinking and research, the answer turned out to be trivial: git rebase -i
takes the editor name from the well-known EDITOR/VISUAL environment variables, so overriding that to point to a non-interactive script does the job.
但是,EDITOR/VISUAL 对提交列表、改写时的提交消息和其他任何内容无动于衷.所以,由于 http://git.kernel.org/?p=git/git.git;a=commit;h=821881d88d3012a64a52ece9a8c2571ca00c35cd ,有一个特殊的环境变量 GIT_SEQUENCE_EDITOR 仅适用于提交列表.
However, EDITOR/VISUAL applies indifferently to the list of commits, commit messages when rewording and anything else. So, since http://git.kernel.org/?p=git/git.git;a=commit;h=821881d88d3012a64a52ece9a8c2571ca00c35cd , there's a special environment variable GIT_SEQUENCE_EDITOR which applies only to the commit list.
因此,重新排序或扁平化提交的方法是:
So, the recipe to re-order or flatten commits is:
运行:GIT_SEQUENCE_EDITOR=