【发布时间】:2019-07-25 15:53:57
【问题描述】:
我目前正在开发一个 iOS 项目。我有一个在构建时运行的脚本。此脚本更新内部版本号并将其提交到 git 并推送它。然而,在使用了几天后,我意识到了一个副作用。我可以有连续的提交,它会增加内部版本号。所以我的提交日志充满了这些提交。由于该项目被分解为几个核心库,因此这种情况变得尤为严重。因此,在库上工作总是会导致构建增量(因为它是同一个工作区)。
我现在意识到我需要一个足够聪明的脚本来压缩连续提交,这些提交是内部版本号的更新。
跑步
git log -20 --pretty=format:"%h - %s"
例如,将产生
6add12a1 - Update the package from handle
70f438be - Updated client version to 0.15.0.2152 and next version to 0.15.0.2153
7d84151f - Updated client version to 0.15.0.2151 and next version to 0.15.0.2152
eace113b - Updated client version to 0.15.0.2150 and next version to 0.15.0.2151
e72624dd - Updated client version to 0.15.0.2149 and next version to 0.15.0.2150
85d15b6c - Updated client version to 0.15.0.2148 and next version to 0.15.0.2149
a4e140cd - Updated client version to 0.15.0.2147 and next version to 0.15.0.2148
ffb18892 - Updated client version to 0.15.0.2146 and next version to 0.15.0.2147
ebd33432 - Updated client version to 0.15.0.2145 and next version to 0.15.0.2146
f0727ca7 - Updated client version to 0.15.0.2144 and next version to 0.15.0.2145
80ab2939 - Adjust balance if FB rewards popup is shown
0c04a1d7 - Updated client version to 0.15.0.2143 and next version to 0.15.0.2144
e89fd769 - Updated client version to 0.15.0.2142 and next version to 0.15.0.2143
c404f9ce - Updated client version to 0.15.0.2141 and next version to 0.15.0.2142
3911fb31 - Updated client version to 0.15.0.2140 and next version to 0.15.0.2141
ee3b7056 - Updated client version to 0.15.0.2139 and next version to 0.15.0.2140
cfb3b2a7 - Updated client version to 0.15.0.2138 and next version to 0.15.0.2139
a11fa3d9 - Add conditionals compilation to remove some logging
b9d0f75a - Disable backlight
ba4447ae - Updated client version to 0.15.0.2137 and next version to 0.15.0.2138
所以在本例中,我想将 70f438be 压缩为 f0727ca7,然后将提交更新为“将客户端版本从 0.15.0.2138 更新为 0.15.0.2152”。
有两件事需要做。
- 编写脚本或手动压缩连续的内部版本号增量提交
- 更新我的脚本以检查以前的提交是否是内部版本号增量,如果是,则压缩。
我自己编写脚本没有问题。而这个问题的重点是 git 命令本身。有关脚本的详细信息作为上下文提供。
我正在寻找的是如何以非交互方式使用 git 来压缩不是从 HEAD 开始的特定连续提交范围。到目前为止,我所看到的所有参考文献都已从 HEAD 中删除。
比如这个。
Is there a way to squash a number of commits non-interactively?.
我将在今天晚些时候再讨论一遍,因为它可能仍然有答案。
哦,是的,澄清一下,这些提交都已经推送了。
请注意,这是在 Mac 上。而后一个脚本是从 Xcode(构建阶段)运行的,是一个使用 GitPython 的 Python 脚本。
【问题讨论】:
标签: git git-rebase