2

我在 Git 中有这个结构

develop      C - D - E
            /
master A - B

然后,我从开发中添加了一个新分支:

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
4

1 回答 1

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 logon的输出new_branch停止在 F 处,但这不是工作方式git log,它将显示连续的提交链及其父项。该链从当前分支开始,但更往后,它并不关心提交“属于”哪个分支(分支实际上只是指向特定提交的指针)。

new_branch如果您想要仅排除提交的日志历史记录,develop则必须git log明确说明,如下所示:

git log develop..new_branch

这将列出提交 F 和 G。

于 2013-05-25T16:52:50.210 回答