Git 为每次提交运行 shell 命令

标签 git shell

我想遍历一系列提交并对每个提交执行 shell 命令。如果命令失败,我希望步行停止,否则继续前进。我查看了 filter-branch,但我不想重写提交,只是检查它们。 for-each-ref 似乎不允许您指定要执行的范围。

我的具体问题是我创建了一堆提交,我想确保每个提交都是可构建的。我想做类似的事情:

git foreach origin/master..master 'git submodule update && make clean && make'

我当然可以编写一个 shell 脚本来执行此操作,但看起来 git 可能有一个很好的方法来执行此操作。

最佳答案

您可以使用带有 exec 选项的交互式 rebase 。

git rebase -i --exec <build command> <first sha you want to test>~

--exec Append "exec " after each line creating a commit in the final history. will be interpreted as one or more shell commands.

Reordering and editing commits usually creates untested intermediate steps. You may want to check that your history editing did not break anything by running a test, or at least recompiling at intermediate points in history by using the "exec" command (shortcut "x").

The interactive rebase will stop when a command fails (i.e. exits with non-0 status) to give you an opportunity to fix the problem.

关于Git 为每次提交运行 shell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26983700/

相关文章:

git svn 在非标准 svn 存储库布局上指定分支和标签

python - merge pull 请求后升级模块

windows - 如何在 shell 脚本中关闭通过其参数定位的 Windows 进程?

android - 有没有办法在 C++ 中以编程方式执行 adb 命令?这部分 C++ 代码是使用 android studio 中的 ndk build 构建的。那里

php - 通过 php 执行 bash 脚本

linux - 如何在Launchy中输入文本并将其附加到文本文件的末尾?

Git 子模块 url 已更改

Git Cherry-Pick 和冲突

git - 当两者都在防火墙/NATs/...之后时,如何在 git 存储库之间推送/pull ?

javascript - Gnome javascript 文档