阻止新分支在Git中获取旧的提交历史记录

时间:2013-05-25 15:27:19

标签: git version-control branch git-branch

我在Git中有这个结构

develop      C - D - E
            /
master A - B

然后,我在develop中添加了一个新的分支:

git checkout -b new_branch develop

这就是我得到的

new_branch C - D - E - F - G
                      /
develop      C - D - E

它分支了,但新分支继承了开发的提交历史,而不是所需的结构:

new_branch        F - G
                 /
develop C - D - E

我怎么能实现这个目标?

编辑:开发日志输出

* 0c5b5fe Deleted changelog
* b20083f Added changelog. Version 1.2 Development
*   b9d888b Merge branch 'ProgressHUD' into develop
|\  
| * e310630 Modified .gitignore to ignore Instrument Tests
| * 9bb7ab7 Deleted code to remove "deletion while loading" functionality.
| * d139fef Fixed a few errors with RecentPhotos loading.
| * 6d52eb1 Added MBProgressHUD to the recents section
| * d98e09e Added MBProgressHUD functionality in the PersonList
| * 4c6fd41 Added MBProgressHUD Files.
* | 2f741e3 Modified .gitignore
|/  
*   ea1b51b Merged in glenwayguy/gitignore-edited-online-with-bitbucket-13693489
|\  
| * bdb0996 .gitignore edited online with Bitbucket
|/  
* 0fb68ec Initial Commit Version 1.1 Release

new_branch日志输出:

* 0c5b5fe Deleted changelog
* b20083f Added changelog. Version 1.2 Development
*   b9d888b Merge branch 'ProgressHUD' into develop
|\  
| * e310630 Modified .gitignore to ignore Instrument Tests
| * 9bb7ab7 Deleted code to remove "deletion while loading" functionality.
| * d139fef Fixed a few errors with RecentPhotos loading.
| * 6d52eb1 Added MBProgressHUD to the recents section
| * d98e09e Added MBProgressHUD functionality in the PersonList
| * 4c6fd41 Added MBProgressHUD Files.
* | 2f741e3 Modified .gitignore
|/  
*   ea1b51b Merged in glenwayguy/gitignore-edited-online-with-bitbucket-13693489
|\  
| * bdb0996 .gitignore edited online with Bitbucket
|/  
* 0fb68ec Initial Commit Version 1.1 Release

1 个答案:

答案 0 :(得分:4)

我认为您正在错误地解释git log的输出。

这不是正确的图片

new_branch C - D - E - F - G
                      /
develop      C - D - E

提交C,D和E 相同,不应在两个不同的地方显示。

这就是你想要的,而且确实是你所拥有的

new_branch        F - G
                 /
develop C - D - E

也许您希望git lognew_branch的输出在F处停止,但这不是git log的工作方式,它会显示连续的提交链及其父级。这个链从当前分支开始,但更进一步,它不关心提交“属于”的分支(分支实际上只是指向特定提交的指针)。

如果您希望仅new_branch的日志历史记录排除develop上的提交,则必须明确告知git log,如下所示:

git log develop..new_branch

这将列出提交F和G.