Test Empty Repository
In this step, we will explore what happens when you run git log
and git rev-list --count HEAD
in a Git repository that has no commits yet. This will help you understand the output you saw in the first lab when you first initialized your repository.
First, let's create a new, empty directory and initialize a Git repository inside it. Make sure you are in the ~/project
directory:
cd ~/project
mkdir empty-repo
cd empty-repo
git init
You should see the message indicating that an empty Git repository has been initialized:
Initialized empty Git repository in /home/labex/project/empty-repo/.git/
Now, let's run git log
in this empty repository:
git log
You will see output similar to this:
fatal: your current branch 'master' does not have any commits yet
This message tells you exactly what's going on: there are no commits in the current branch (master
). git log
needs commits to display a history, so it reports that there's nothing to show.
Next, let's try git rev-list --count HEAD
:
git rev-list --count HEAD
This time, the output will be:
0
This makes sense! Since there are no commits, the count of commits reachable from HEAD
is zero.
Comparing the output of these commands in an empty repository versus our my-time-machine
repository (which has one commit) helps solidify your understanding of what these commands do. git log
shows the details of commits, while git rev-list --count
gives you a simple count. Both commands accurately reflect the state of the repository's history.
You can now remove the empty-repo
directory as we won't need it for the next steps:
cd ~/project
rm -rf empty-repo