git log
In the last article, we just created our first commit. Each commit that you make can be considered as a checkpoint in your project journey. We're going to keep track of the history our commits using the git log
method.
git log
>> commit e878e0f23836e0bf0f3ca35a85758eb55672aff6 (HEAD -> master)
Author: John Doe <johndoe@gmail.com>
Date: Sun Oct 18 12:15:43 2020 -0400
Initial Commit
This command displays the commit we recently created. Each commit log includes:
-
The SHA-1 Hash Value: e878e0f23836e0bf0f3ca35a85758eb55672aff6
-
The Author: John Doe johndoe@gmail.com
-
The Date: Sun Oct 18 12:15:43 2020 -0400
-
The Commit Message: Initial Commit
The Sha-1 Hash Value is git's way of identifying each commit. It allows us to uniquely identify each commit no matter what changes are made to the repository.
Creating Another Commit
Let's make a change to our files and create another commit, you can make these changes manually by opening your files and writing in them, or you can just do it in the terminal:
echo "Random Message 1" >> test-file.txt
echo "Random Message 2" >> file-.txt
echo "Random Message 3" >> file-3.txt
let's verify the status of our working directory:
git status
>> On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file-2.txt
modified: file-3.txt
modified: project-1.txt
no changes added to commit (use "git add" and/or "git commit -a")
The status of our repository tells us that file-2.txt
file-3.txt
project-1.txt
have been modified but not staged: Changes not staged for commit.
Let's stage all our files:
git add .
git status
>> On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file-2.txt
modified: file-3.txt
modified: project-1.txt
The output above suggests that our files have been staged.
Let's create our second commit:
git commit -m "This is our second commit, random text was added to files"
let's observe the history of our commits:
git log
>> commit 0475c74a22cd4189ada0cc0a8d16a61192a470b8 (HEAD -> master)
Author: jad slim <jadslimm@gmail.com>
Date: Sun Oct 18 13:43:49 2020 -0400
This is our second commit, random text was added to files
commit e878e0f23836e0bf0f3ca35a85758eb55672aff6
Author: Jad <jad_slim@live.com>
Date: Sun Oct 18 12:15:43 2020 -0400
Initial Commit
our log has successfully registered two commits
The commit message
A commit message should be used to describe the general changes that were made. It's important to keep the messages very short. Do not overwhelm the commit messages with too many details, as it will make things very confusing once your commits pile up.