Conteúdo do Curso
Git Essentials
Git Essentials
Viewing Commit History
Understanding the commit history of a Git repository is fundamental to effective version control and collaboration. There are various commands and techniques to navigate and comprehend the commit history of a Git project, but, as for now, we’ll discuss only the git log
command.
Git Log
The primary command for viewing commit history is git log
. This command displays a chronological list of commits, providing essential information for each commit.
Basic Usage
This command displays the commit history from the latest to the earliest. You can navigate through the log using arrow keys and exit by pressing q.
Let’s run git log
in our project directory:
As you can see, all of the three commits we have made so far are displayed.
Output Details
Despite the output taking rather few lines, it contains quite a lot of information for each commit. Here are these elements (from top to bottom):
- commit hash (unique commit identifier);
- author (name and email of the person who made the commit);
- date and time the commit was made;
- commit message.
Customizing the Output
We can also limit the number of commits displayed using the git log -n
command. For example, the following command will display only the 2 latest commits:
Moreover, it is possible to condense each commit to a single line, showing only the commit hash and the commit message using the following command:
Let’s run both of these commands in the terminal:
Note
When running the
git log --oneline
command the hashes of the commits are not displayed entirely. Instead, only the symbols, which uniquely identify the commit, are displayed.
Obrigado pelo seu feedback!