Git:在不污染主分支历史记录的情况下合并分支

3

好的,所以:

在svn和bzr中,我可以进行分支、提交、合并操作,我的提交历史将如下所示:

41: Theodore R. Smith 2013-09-14 Jump to list by name instead of number.
40: Theodore R. Smith 2013-09-14 [merge] [m] Miscellaneous cleanups.
  39.1.4: Theodore R. Smith 2013-09-14 [m] Removed old files.
  39.1.3: Theodore R. Smith 2013-09-14 [m] Fixed bug where test could not...
  39.1.2: Theodore R. Smith 2013-09-14 [m] Fixed a CSS layout bug from th...
  39.1.1: Theodore R. Smith 2013-09-14 [m] Fixed a typo.
39: Theodore R. Smith 2013-09-14 Added a progress bar.
38: Theodore R. Smith 2013-09-14 [merge] Updated the core libraries.
  37.1.3: Theodore R. Smith 2013-09-14 Updated HTML Kickstarter.
  37.1.2: Theodore R. Smith 2013-09-14 Upgraded to from jQuery 1.8.3 to 2.0.3.
  37.1.1: Theodore R. Smith 2013-09-14 Upgraded to jQuery Address v1.6.

如果我不想展开历史记录,可以做如下操作:

41: Theodore R. Smith 2013-09-14 Jump to list by name instead of number.
40: Theodore R. Smith 2013-09-14 [merge] [m] Miscellaneous cleanups.
39: Theodore R. Smith 2013-09-14 Added a progress bar.
38: Theodore R. Smith 2013-09-14 [merge] Updated the core libraries.

我可以随时通过 bzr diff -r37.1.2..37.1.3 很容易地获取合并提交的差异等信息。

重要的是,我的分支历史被保留,而我的主线提交历史没有被小功能提交污染。

但是,无论我在git中进行特性合并与否,使用或不使用 --no-ff,我的提交历史都会出现以下情况:

<hash>: Theodore R. Smith 2013-09-14 Jump to list by name instead of number.
<hash>: Theodore R. Smith 2013-09-14 [merge] [m] Miscellaneous cleanups.
<hash>: Theodore R. Smith 2013-09-14 [m] Removed old files.
<hash>: Theodore R. Smith 2013-09-14 Added a progress bar.
<hash>: Theodore R. Smith 2013-09-14 [m] Fixed bug where test could not...
<hash>: Theodore R. Smith 2013-09-14 [merge] Updated the core libraries.
<hash>: Theodore R. Smith 2013-09-14 [m] Fixed a CSS layout bug from th...
<hash>: Theodore R. Smith 2013-09-14 Updated HTML Kickstarter.
<hash>: Theodore R. Smith 2013-09-14 [m] Fixed a typo.
<hash>: Theodore R. Smith 2013-09-14 Upgraded to from jQuery 1.8.3 to 2.0.3.
<hash>: Theodore R. Smith 2013-09-14 Upgraded to jQuery Address v1.6.

我的疑问有以下几点:
  1. 所有的功能性小提交都在主线历史记录中,这是怎么回事?
  2. 功能性小提交在主线历史记录中混乱无序。它们好像被固定在原始提交时间上,而不是合并时间。
  3. 修订ID没有立即的数字排名,只有随机哈希值。但我敢打赌这是无法修复的。
  4. 如果只看这个,我无法确定一个功能分支何时开始或结束。
我想要的解决方案是:
  1. 保留所有提交历史,并让我查看小的功能性提交差异。这对于代码取证很重要。所以,git rebase和git merge --squash都不能用。
  2. 不污染主线提交日志。这可能是最严重的问题。
  3. 根据合并时间保持所有提交的正确顺序。请不要让小的提交混杂在一起。
  4. 最好能够让我查看所有小的功能性提交,并按正确的顺序与主线历史记录一起查看,就像bzr那样。虽然我不介意只能使用类似git log这样的命令来查看此信息。
谢谢您帮助我理解这个过于复杂的程序!

可能是合并GIT分支而不包含提交日志的重复问题。 - con-f-use
1个回答

11

Git和Bazaar的图形完全相同,我知道这一点,因为我编写了Git官方的Bazaar桥接程序,唯一的区别是通过log命令呈现图形的方式。

git log有大量选项,因此可以指定要如何呈现该图形。

看起来你想要的是这个:

git log --oneline --graph

这将以与 bzr log 相似的方式显示合并:

*   eaaec50 Merge git://github.com/git-l10n/git-po
|\  
| * 1b5f46f l10n: Add reference for french translation team
| * 6b388fc l10n: fr.po: 821/2112 messages translated
* |   2809258 Merge branch 'sb/mailmap-updates'
|\ \  
| * | cdb6b5a .mailmap: Combine more (name, email) to individual persons
| * | 10813e0 .mailmap: update long-lost friends with multiple defunct addresses
* | | 8ed205a git-remote-mediawiki: ignore generated git-mw
| |/  
|/|   
* |   96cb27a Merge branch 'maint'

你也可以完全忽略“小提交”

git log --oneline --first-parent

eaaec50 Merge git://github.com/git-l10n/git-po
2809258 Merge branch 'sb/mailmap-updates'
8ed205a git-remote-mediawiki: ignore generated git-mw
96cb27a Merge branch 'maint'

如果你厌倦了输入所有这些选项,你可以配置一个别名:

git config --global alias.l 'log --oneline --graph'

所以你只需要输入 git l


为什么这不是默认设置?特别是在Github上 :o - Theodore R. Smith
非常感谢!我终于有了一个可用的Git日志;它不能与GitHub一起使用,但没关系,对吧? - Theodore R. Smith
更好的是,您可以使用--decorate选项。 - FelipeC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接