我正在尝试根据git log构建历史报告。但是我想跳过除master之外的分支,即使它们被合并了。例如,我创建了分支以使用功能X.在这个分支中有很多小提交,我不喜欢在报告中看到这些小步骤。但是当我将这个分支合并到主人并且消息“功能X实现”时,我想在报告中看到这个里程碑。感谢您帮助git newbie。
答案 0 :(得分:3)
如果要合并分支而不合并该分支的整个提交历史记录,可以使用--squash
命令merge
。这将应用从该分支到工作目录的所有更改,而不实际创建任何提交;此时,您可以为整个历史记录生成一个提交。所以,如果你有master
分支看起来像这样:
commit 69b2303df9884627ade245fff4a3376f39646cbd
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:24:56 2012 -0400
commit on master
commit c8496d9ac4048a414faffb91486075ab0952e2d7
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:24:43 2012 -0400
initial commit
另一个分支newbranch
看起来像这样:
commit 71587063a73368ea160a78cd6d130f828cb05e0e
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:25:36 2012 -0400
commit 3 on new branch
commit 37ab4fc91c796ed05ecae0c8f504f263cee9603d
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:25:36 2012 -0400
commit 2 on new branch
commit 5fd0768e355d1cba0905aaed327fb20ef263d6ef
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:25:36 2012 -0400
commit 1 on new branch
commit 69b2303df9884627ade245fff4a3376f39646cbd
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:24:56 2012 -0400
commit on master
commit c8496d9ac4048a414faffb91486075ab0952e2d7
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:24:43 2012 -0400
initial commit
然后你可以这样做:
git checkout master
git merge --squash newbranch
git commit -m "merged changes from newbranch"
然后master
分支的日志将如下所示:
commit 0737d3dac5f769f837d4d0ce90ba1004c79d6a92
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:26:29 2012 -0400
merged newbranch into master
commit 69b2303df9884627ade245fff4a3376f39646cbd
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:24:56 2012 -0400
commit on master
commit c8496d9ac4048a414faffb91486075ab0952e2d7
Author: Lars Kellogg-Stedman <lars@seas.harvard.edu>
Date: Mon May 14 13:24:43 2012 -0400
initial commit
答案 1 :(得分:1)
如果我理解正确的话,你所寻找的内容实质上是合并到主人的列表。
如果这是正确的,那么我相信这会奏效:
git checkout master
git log --merges