charleyh
charleyh

Reputation: 2063

Stop new branch from getting old commit history in Git

I had this structure in Git

develop      C - D - E
            /
master A - B

Then, I added a new branch from develop with:

git checkout -b new_branch develop

This is what i got

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

It branched off, but new branch inherited the commit history of develop, instead of the desired structure:

new_branch        F - G
                 /
develop C - D - E

How could I achieve this?

Edit: develop log output

* 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 log output:

* 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

Upvotes: 2

Views: 833

Answers (1)

Klas Mellbourn
Klas Mellbourn

Reputation: 44397

I think you are interpreting the output of git log incorrectly.

This is not the correct picture

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

Commits C, D and E are identical, and should not be shown in two different places.

This is what you desire, and it is indeed what you have

new_branch        F - G
                 /
develop C - D - E

Perhaps you expect the output of git log on new_branch to stop at F, but that is not the way git log works, it will show a continuous chain of commits and their parents. This chain starts at the current branch, but further back, it does not care what branch the commits "belong" to (a branch is actually just a pointer to a specific commit).

If you want the log history of just new_branch excluding the commits on develop, you have to tell git log that explicitly, like this:

git log develop..new_branch

This will list commits F and G.

Upvotes: 4

Related Questions