Displays the commit history of the repository.
| Option | Description |
|---|---|
| --oneline | Display each commit on a single line |
| --graph | Display branch and merge history as an ASCII graph |
| --decorate | Show references (branches, tags, etc.) |
| --all | Show commits from all branches |
| -p, --patch | Show the diff for each commit |
| -n <number> | Limit the number of commits displayed |
| --author=<pattern> | Show only commits by specific author |
| --since=<date>, --after=<date> | Show commits more recent than specified date |
| --until=<date>, --before=<date> | Show commits older than specified date |
Examples:
git log - Display commit historygit log --oneline - Display commit history in a concise formatgit log --oneline --graph --all - Display commit history for all branches in graph formatgit log -p - Display commit history including diffsgit log -n 5 - Display only the 5 most recent commitsgit log --author="John" - Display only commits by Johngit log --since="2023-01-01" - Display commits since January 1, 2023git log file.txt - Display commit history for a specific file
Displays changes between files.
| Option/Argument | Description |
|---|---|
| (no arguments) | Show differences between working directory and staging area |
| --staged, --cached | Show differences between staging area and the latest commit |
| <commit1> <commit2> | Show differences between two commits |
| --name-only | Show only names of changed files |
| --name-status | Show names of changed files and their status (added/modified/deleted) |
| --color-words | Highlight changes at word level |
Examples:
git diff - Show differences between working directory and staging areagit diff --staged - Show differences between staging area and the latest commitgit diff HEAD - Show differences between working directory and the latest commitgit diff HEAD~1 HEAD - Show differences between the latest commit and the previous commitgit diff main feature - Show differences between main branch and feature branchgit diff -- file.txt - Show differences for a specific file only
Understanding the output of git diff commands is essential for accurately interpreting changes. Here's a guide to reading diff output.
diff --git a/filename b/filename
index hash1..hash2 mode
--- a/filename
+++ b/filename
@@ -startline,count +startline,count @@ context info
- deleted line
+ added line
unchanged line
diff --git a/example.txt b/example.txt
index abc1234..def5678 100644
--- a/example.txt
+++ b/example.txt
@@ -1,5 +1,6 @@
This is an unchanged line.
-This line was deleted.
+This line was added.
+This is another added line.
This is also an unchanged line.
-This line was also deleted.
+This line was modified.
This is the last unchanged line.
In this example: