代码之家  ›  专栏  ›  技术社区  ›  Theodore R. Smith

Git:在不污染Master历史的情况下在分支中合并

  •  3
  • Theodore R. Smith  · 技术社区  · 12 年前

    好的,所以:

    在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.
    

    在任何时候,我都可以获得单个合并提交的diff等 相当地 简单,通过 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. 根据合并时间将所有commit保持在正确的顺序中。拜托,我不能让小的提交混合匹配。
    4. 最理想的情况是,我至少可以按正确的顺序看到所有的次要功能提交,以及主线历史记录,比如bzr是如何做事的,尽管我不介意只能通过钻入命令查看这些信息,比如 git log .

    谢谢你帮助我理解这个过于复杂的程序!

    1 回复  |  直到 12 年前
        1
  •  11
  •   FelipeC    12 年前

    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 .