Git Tutorial menu

Git History and Changes

One of Git's best features is its history. You can see every change ever made to your project.

git log

Example

bash
git log
Output
commit 8b41d07c2e9a5f13b6d0e8a4c7f21b9d3e6a5c10 (HEAD -> main)
Author: Ayesha Khan <ayesha@example.com>
Date:   Thu Oct 15 10:42:11 2026 +0500

    Add basic stylesheet

commit 3f2a9c14d8e7b6a5f0c3d2e1b9a8f7e6d5c4b3a2
Author: Ayesha Khan <ayesha@example.com>
Date:   Thu Oct 15 10:30:05 2026 +0500

    Add home page

The newest commit is at the top. HEAD -> main shows where you are now. Press q to leave the log if it fills the screen.

Shorter Logs

CommandShows
git log --onelineOne line per commit
git log -3Only the last 3 commits
git log --oneline --graph --allA drawing of all branches
git log --author="Ali"Commits by one person
git log -- style.cssCommits that changed one file

Example

bash
git log --oneline
Output
8b41d07 (HEAD -> main) Add basic stylesheet
3f2a9c1 Add home page

git diff

git diff shows exactly which lines changed. Edit index.html, then:

Example

bash
git diff
Output
diff --git a/index.html b/index.html
index 4c2a1b0..9e8d7f6 100644
--- a/index.html
+++ b/index.html
@@ -1,3 +1,3 @@
 <html>
-<h1>Welcome</h1>
+<h1>Welcome to Ali's Bakery</h1>
 </html>

Lines starting with - were removed, and lines starting with + were added.

CommandCompares
git diffWorking files with the staging area (unstaged changes)
git diff --stagedStaging area with the last commit (what you are about to commit)
git diff 3f2a9c1 8b41d07Two commits
git diff main featureTwo branches

Run git diff --staged before every commit. It is a quick check that you are committing only what you meant to.

git show

See the full details and changes of one commit:

Example

bash
git show 3f2a9c1

You do not need to type the whole hash; the first 7 characters are enough.

Who Changed This Line?

git blame shows, for each line of a file, the last commit and author that changed it:

Example

bash
git blame index.html
Output
3f2a9c14 (Ayesha Khan 2026-10-15 10:30:05 +0500 1) <html>
a91c3e72 (Ali Raza    2026-10-15 11:05:40 +0500 2) <h1>Welcome to Ali's Bakery</h1>
3f2a9c14 (Ayesha Khan 2026-10-15 10:30:05 +0500 3) </html>

It is useful in a team when you want to ask someone why a line was written.

HEAD is a pointer to the commit you are working on, usually the latest commit of your current branch. You can refer to older commits from it:

  • HEAD is the current commit
  • HEAD~1 is one commit before
  • HEAD~3 is three commits before

Example

bash
git diff HEAD~1 HEAD

This shows what changed in the most recent commit.

Exercise

Exercise

Which command shows each commit on a single short line?

Learn Git with a teacher

Join the Full Stack Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp