Git为每个提交运行shell命令 [英] Git run shell command for each commit

查看:87
本文介绍了Git为每个提交运行shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to walk through a range of commits and perform a shell command on each. If the command fails, I would like the walk to stop, otherwise keep going. I have looked at filter-branch, but I don't want to re-write the commits, just check them out. for-each-ref does not seem to allow you to specify a range to act on.

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

My specific problem is that I created a bunch of commits and I would like to ensure that each commit is buildable. I would like to do something like:

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

我当然可以编写一个shell脚本来完成这个任务,但它看起来像是git可能有一个很好的方法。

I could of course write a shell script to do this, but it seems like the sort of thing that git might have a nice way to do.

推荐答案

您可以使用交互式rebase和exec选项。

You can use interactive rebase with an exec option.

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




<每行在最终历史记录中创建提交后的exec。将被解释为一个或多个shell
命令。

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

重新排序和编辑提交通常创建未经测试的中间
步骤。您可能需要检查历史编辑是否通过运行测试或者至少使用exec命令(快捷方式x)重新编译历史中的
点来破坏
任何内容。

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").

当命令失败时(即以
非0状态退出),交互式重新分配将停止,以便您解决问题。

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命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆