After making your first commit, you've officially started recording your project's history. But how do you look back at the changes you've saved? Git provides the git log
command for exactly this purpose. Think of it as your project's detailed journal, chronicling every significant change saved as a commit.
Running the git log
command in your terminal, within your repository directory, will display a chronological list of commits, starting with the most recent one.
cd your-repo-directory
git log
The output for each commit typically looks something like this:
commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 (HEAD -> main)
Author: Your Name <your.email@example.com>
Date: Tue May 21 10:30:00 2024 +0000
Initial commit: Add project structure
commit f9e8d7c6b5a4f3e2d1c0b9a8f7e6d5c4b3a2f1e0
Author: Your Name <your.email@example.com>
Date: Tue May 21 09:45:15 2024 +0000
Add README file
Let's break down the information presented for each commit:
a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0
) is the commit's unique identifier, technically a SHA-1 hash. This ID guarantees the integrity of the commit and allows Git (and you) to refer to specific points in history. You usually only need the first 7-10 characters to uniquely identify a commit in practice. The (HEAD -> main)
part indicates that HEAD
(your current position in the project history) is pointing to the main
branch, and this commit is the latest one on that branch. We'll discuss branches and HEAD
more later.user.name
and user.email
configuration you set up earlier.git commit -m "Your message"
. As you can see, clear messages (like discussed in "Writing Good Commit Messages") make the log much more informative.The default git log
output is informative, but it can be quite verbose, especially as your project grows. Git offers many options to customize the output to show precisely what you need. Here are a few common and useful ones:
--oneline
To get a very compact view, use the --oneline
option. It shows only the first part of the commit hash and the commit message subject line for each commit:
git log --oneline
Output:
a1b2c3d (HEAD -> main) Initial commit: Add project structure
f9e8d7c Add README file
This is helpful for quickly getting an overview of recent changes.
--stat
If you want to see which files were changed in each commit and a summary of how many lines were added or removed, use the --stat
option:
git log --stat
Output:
commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 (HEAD -> main)
Author: Your Name <your.email@example.com>
Date: Tue May 21 10:30:00 2024 +0000
Initial commit: Add project structure
src/app.js | 1 +
src/style.css | 1 +
2 files changed, 2 insertions(+)
commit f9e8d7c6b5a4f3e2d1c0b9a8f7e6d5c4b3a2f1e0
Author: Your Name <your.email@example.com>
Date: Tue May 21 09:45:15 2024 +0000
Add README file
README.md | 5 +++++
1 file changed, 5 insertions(+)
This shows the file paths relative to the project root, along with a simple visual representation (+
for additions, -
for deletions) and a summary line.
--patch
(-p
)To see the exact changes (the "diff" or "patch") introduced by each commit, use the -p
or --patch
option:
git log -p
Output (excerpt for one commit):
commit a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 (HEAD -> main)
Author: Your Name <your.email@example.com>
Date: Tue May 21 10:30:00 2024 +0000
Initial commit: Add project structure
diff --git a/src/app.js b/src/app.js
new file mode 100644
index 0000000..e69de29
diff --git a/src/style.css b/src/style.css
new file mode 100644
index 0000000..e69de29
This output shows the differences in a format similar to the diff
command. Lines starting with +
were added, and lines starting with -
were removed (though none were removed in this simple example of new files). This option is very detailed and useful for understanding specific changes but can produce a lot of output.
If you only want to see the last few commits, you can use the -n
option, followed by the number of commits you want to view. For example, to see only the latest three commits:
git log -n 3
You can combine these options. For instance, to see a concise view of the last two commits with stats:
git log --oneline --stat -n 2
Output:
a1b2c3d (HEAD -> main) Initial commit: Add project structure
src/app.js | 1 +
src/style.css | 1 +
2 files changed, 2 insertions(+)
f9e8d7c Add README file
README.md | 5 +++++
1 file changed, 5 insertions(+)
The git log
command is your window into the history you are building with git commit
. Experimenting with these options will help you navigate and understand your project's evolution effectively. As you progress, you'll find git log
to be an indispensable tool for reviewing changes, finding when specific modifications were introduced, and understanding the work of collaborators.
© 2025 ApX Machine Learning