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

标签 git version-control branch git-branch

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

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

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

最佳答案

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

这不是正确的图片

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

提交 C、D 和 E 相同,不应显示在两个不同的位置。

这是你所渴望的,也是你所拥有的

new_branch        F - G
                 /
develop C - D - E

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

如果您只想要 new_branch 的日志历史记录(不包括 develop 上的提交),则必须明确告诉 git log,如下所示:

git log develop..new_branch

这将列出提交 F 和 G。

关于git - 阻止新分支获取 Git 中的旧提交历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16751046/

相关文章:

php - 版本控制 PHP Web 项目

version-control - 源代码控制概念 - 每个功能分支,每个 checkin 标记

Git 克隆、推送和 pull Ubuntu 服务器上的多个用户

python - Git:保持同一文件的两个位置同步

git - 有没有办法将 azure synapse studio 连接到 bitbucket repo?

gitlab 不发送邮件(队列仍在增长)

haskell:在 ghc 之间切换(对于不同的基础)有哪些好方法?

repository - Mercurial-是否可以在同一仓库中 merge 从主干到分支的更改?

TFS:分支时如何维护项目引用

branch - Perforce:如何在多个分支机构之间进行集成?