问题描述
我们有一个相当大(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 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
命令中指明您描述的组合。