【问题标题】:Collapse git history to tags (combine commits between tags)将 git 历史记录折叠到标签(在标签之间合并提交)
【发布时间】:2021-09-17 22:58:34
【问题描述】:

我们有一个相当大的(1000 多个提交)存储库,其中包含 7 年的更改和 6 个发布版本(每个版本由一个 git 标签表示)。我们想折叠历史记录,以便在最后一个标签之前,两个标签之间的所有提交都折叠成一个提交,带有版本标签。从而将我们的存储库历史记录减少到大约 15 次提交。我们不会跨版本进行任何还原。 作为奖励,理想情况下,我们希望将所有提交我们崩溃的人保留为co-authored-by。如果它很重要,我们没有任何从标签之前跳过标签进入新版本的合并。

发件人:

CHEAD
C2
C3
...
TAG6
Cx
Cy
...
TAG5
Ca
..

进入

CHEAD
C2
C3
...
TAG6
TAG5
TAG4
TAG3
TAG2
TAG1

关于如何进行的任何想法?

【问题讨论】:

  • 在您要按原样保存的第一个提交上从一个新分支开始 - 然后将每个标签合并到该分支上并强制移动标签。重复直到到达最后一个标签,然后在新分支上重播最后几次提交。删除旧分支并可选择将新分支重命名为与旧分支相同的名称。然后确保所有的克隆都是更新的,否则你可能会很难解决。

标签: git git-history git-history-rewrite


【解决方案1】:

按标签折叠很容易:git log 有两个选项--simplify-by-decoration--decorate-refs=<pattern>,您可以按如下方式使用:

# --graph is useful to have a clear view of parent <-> child relation,
# you may use --oneline to have a compact view, or drop it if you want the complete
# commit messages
git log --graph --oneline --simplify-by-decoration \
      --decorate-refs=refs/tags   # <- this indicates 'keep only tags'

获得“TAG6 之后的所有内容,只有TAG6 之前的标签”的一种部分方法可能是通过两个命令获取日志:

# in a 'mylog' script :
#!/bin/bash

log_history () {
    # get all from TAG6 up to HEAD :
    git log --decorate --graph TAG6..HEAD
    # get only tags up to TAG6 :
    git log --decorate --graph --simplify-by-decoration \
        --decorate-refs=refs/tags TAG6
}

# combine the two commands, and pipe them in your pager
# if you pipe the output of 'git log', git removes the default '--decorate',
# that's why I added it in the commands above
log_history | less

上面将为您提供您想要查看的提交的完整列表;唯一缺少的部分是,在图中,TAG6 与其子提交(TAG6 正上方的提交)之间的链接不会被绘制。

我不知道如何在一个 git log 命令中指出您描述的组合。

【讨论】:

  • 嗯,我觉得有误会。我实际上正在寻找折叠历史的方法,例如“将两个标签之间的所有提交合并为一个提交”。下面的列表不是所需的屏幕输出,而是实际所需的 repo 树。
  • @mmix:你的意思是:你想重写 repo 的历史,让它看起来像这样吗?
  • 是的,就是这个想法。有点像我们要使用整个 repo 的 rebase -i ,然后选择标记提交并修复所有中间(另外,我们希望将该空间中的每个人添加到共同创作中
猜你喜欢
  • 2017-04-19
  • 2023-02-09
  • 2021-09-13
  • 2011-11-08
  • 1970-01-01
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多