Here is a quick overview of where I am in My Git Journey:
- I installed Git for Windows
- I created a new repository
- I staged some content to the local repository
Remember, the general workflow is: Working Directory è Staging à Local Repository à Remote Repository. I’m ready now to move my files from the staging area to my local repository. This is referred to as a commit.
I’m going to use the following statement to commit to my local repository:
git commit -m “My first commit”
The “-m” allows me to define a message that is tagged to my commit.
The above image shows the output results of the commit. It shows the branch name, in this case master. The phrase root-commit indicates that this is the first commit into this repository. And the characters acfb78e represent the first seven characters of the SHA1 for the commit.
Like I’ve done before, let’s go see what’s happened in the repository itself.
There is a new file called COMMIT_EDITMSG. This file contains the commit message from the last commit performed. If I open this file, I’ll find the phrase “My first commit”.
If I drill down into the objects folder, I see the following:
If you remember from my staging post, when I staged my files, it created the 44/ and 50/ folders. I now have two new folders: 84/ and ac/. Notice anything about the ac/ folder? ac is the first two characters of the SHA1 for the commit.
Now let’s go make a change to one of the files (file1.c), then stage and commit the file:
Notice how I use “-am” to both stage and commit the file. Also notice the SHA1 value for the commit that is returned: a382f51. If I go and look in the objects folder, I’ll find a folder that starts with a3. This folder must be related to my commit in some way.
I can use the command cat-file to get more information about the SHA1 values in Git.
If I take the latest SHA1 fragment (a382f51), and run git cat-file -t a382f51, git returns the value commit. “-t” is the type option. You use this to show the type of the object related to the SHA1 value.
If instead I use the “-p” option, it shows me some more detailed information about the object. In this case, it gives me the details of the commit. I’m given the SHA1 values for the tree (more about trees in my next post) and the parent, as well as information on who performed the commit, and the commit message.
Let’s take the first 7 letters of the tree SHA1 value and see what we get from cat-file:
This shows us the two files we have been working with along with their SHA1 values. The numbers in front (100644) indicate these are files. I’ll dive into that some other time. Also, notice the SHA1 value for file1.c. It starts with 84, which corresponds to the /84 folder I saw earlier in the objects folder. Remember, with the latest commit I did, I only modified file1.c. Git must create new folders for a file each time it is modified, which makes sense, as it is calculating a new SHA1 value for the file.
Finally, I can use cat-file against the first 7 characters of the SHA1 for a file:
And it shows me the contents of the file.
And here we are. We have now taken some files and moved them through the basic process from editing to staging to committing to the local repository.