Table of contents
No headings in the article.
As of now we have read about basics of git, github, architecture of git and even some hands on with git commands.
But now, let's discuss about git branches, snapshots and git internals.
Commit object
As we have studied earlier about committing changes, let's know what is commit object.A commit object contains :
About parent commits
0 parent = initial commit1 parent = usual commit
multiple parents = commit resulting from merging 2 or more branches.
What happens when we stage a file?
Let's see what happens at the staging time:
What happens when we commit a file?
When you make a commit, git stores a commit object that contains a pointer to the snapshot of the content you staged.This statement in itself is very much overwhelming, but let's discuss it with a diagram.
Following happens upon committing a file:
Now we have commit, tree and something called blob.
commit
The files which are present in the staging area and needs to be committed.It has some size , some SHA-1 hash ID of tree , author and committer , and is the first commit of the project.Pointing towards something called tree.
tree
A Git tree object creates the hierarchy between files in a Git repository. You can use the Git tree object to create the relationship between directories and the files they contain. These endpoints allow you to read and write tree objects to your Git database on GitHub. We can again see size and some blobs and their SHA-1 hash ID and their names pointing towards multiple blobs.blob
A Git blob(binary large object) is the object type used to store the contents of each file in a repository. The file's SHA-1 hash is computed and stored in the blob object.
There is some size, and the details about the files.
Branches
Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug(no matter hpw big or small) you spawn a new branch to encapsulate your changes. Branches are cheap and easy to merge. Switching back and forth the branches is also very easy.$ git branch testing
: This lets us create a branch named testing, but the head is still pointing towards master branch (head---->master).
But now we want to change the head from master to the testing branch.
$ git checkout testing
: Let's us change head from master----->testing.
Now as the head is on testing branch, let's do some changes. Diagrammatically it's shown below:
Again if we shift the head from testing----->master using the command $ git checkout master
we'll see , the master would still be at the commit where it was earlier , but now with head at the master branch we'll commit some changes which diagrammatically is shown below:
Here the diagram explains us everything that is happening (common commit, snapshots to merge and so on).
That's pretty much it about the branches, git internals, tree, blobs, commits and head. With this we have gained a lot of knowledge about git and github. Hope you like this blog by me. Do consider liking it and sharing it with your friends.
Connect with me: Twitter
Thank You.