Understanding Git
Posted: Thu Sep 24, 2015 2:09 am
OK, there's a ton of information I'd like to go over here, but I'll try to keep it short and to the point and only cover one topic at a time.
First let me explain what this beautiful little piece of art is supposed to be. It's a diagram showing a project that was branched twice, and how the different merges take place.
The project starts at point X. The black bar represents the 'master' branch, while blue and red represent different branches (and will be referred to be color for clarity sake).
Each circle on the diagram represents a commit into that branch.
When a merge takes place, the color of the line (as well as the related commit) will be that of the origin, or 'from', branch.
Note that a merge will look like an extra commit on the receiving branch, hence the reason they are circles.
So to understand how and when commits hit the different branches, we're going to step through this together. Our first commit into the project is point A. The blue branch is created at this point (but does not have any new commits added to it for quite some time). That is, both master and blue branches contain everything up to the A commit.
The master branch has commit B added to it, and then the red branch is split from this commit. As of this time, both master and red branches contain X, A, B, while the blue branch only contains X and A.
Commits C and D are created into master and blue respectively at roughly the same time, however, no merges have yet taken place. As of now, master contains X, A, B, and C while blue still only contains X, A, and D.
Finally, our first merge takes place, merging commit D from blue into master at the point that I for some reason forgot to name. blue branch remains unchanged but master now contains D in addition to all previous commits.
Master now has a new commit (E) added and then merges into red at point F. Because when we merge we are including all commits up until that point, both master and red branch now contain X, A, B, C, D, and E commits, while blue is still only X, A, and D.
Commit G is added to red and then merged into blue branch at point H (notice we skipped over the black line). Red and blue branches are now contain all commits (the commits from red are moved into blue, but since red also contains the commits from master, we move those over as well). Since nothing was merged into master yet, it still only has up to E.
Does this help explain how commits and merging into multiple branches work?
First let me explain what this beautiful little piece of art is supposed to be. It's a diagram showing a project that was branched twice, and how the different merges take place.
The project starts at point X. The black bar represents the 'master' branch, while blue and red represent different branches (and will be referred to be color for clarity sake).
Each circle on the diagram represents a commit into that branch.
When a merge takes place, the color of the line (as well as the related commit) will be that of the origin, or 'from', branch.
Note that a merge will look like an extra commit on the receiving branch, hence the reason they are circles.
So to understand how and when commits hit the different branches, we're going to step through this together. Our first commit into the project is point A. The blue branch is created at this point (but does not have any new commits added to it for quite some time). That is, both master and blue branches contain everything up to the A commit.
The master branch has commit B added to it, and then the red branch is split from this commit. As of this time, both master and red branches contain X, A, B, while the blue branch only contains X and A.
Commits C and D are created into master and blue respectively at roughly the same time, however, no merges have yet taken place. As of now, master contains X, A, B, and C while blue still only contains X, A, and D.
Finally, our first merge takes place, merging commit D from blue into master at the point that I for some reason forgot to name. blue branch remains unchanged but master now contains D in addition to all previous commits.
Master now has a new commit (E) added and then merges into red at point F. Because when we merge we are including all commits up until that point, both master and red branch now contain X, A, B, C, D, and E commits, while blue is still only X, A, and D.
Commit G is added to red and then merged into blue branch at point H (notice we skipped over the black line). Red and blue branches are now contain all commits (the commits from red are moved into blue, but since red also contains the commits from master, we move those over as well). Since nothing was merged into master yet, it still only has up to E.
Does this help explain how commits and merging into multiple branches work?