Beginner LevelGit & GitHub
How do git log and git show inspect commit history and file diffs?
❓ Interview Prompt: Explain inspecting repository history using git log options (--oneline, --graph, -n) and git show <commit-hash>.
Inspecting historical commits and line modifications relies on two primary commands:
1. 'git log':
Displays historical commits in reverse chronological order:
•
'git log --oneline': Compact single-line view showing short SHA hash and commit message.
•
'git log --graph --oneline --all': Renders an ASCII visual tree graph of branch merges and splits.
•
'git log -n 5': Limits output to the 5 most recent commits.
2. 'git show <commit-hash>':
Displays full detailed metadata (author, date, commit message) and the complete unified code diff introduced by that specific commit.
Code Implementation Example
bash
# Display clean visual branch history graph
git log --graph --oneline --all -n 10
# Inspect detailed diff introduced by specific commit hash
git show a1b2c3d💡Visualizing commit history graphs with git log and inspecting specific diffs with git show.
🎯 Interview Key Takeaway
Use git log --oneline --graph to visualize branch DAG graphs, and git show <hash> to view individual commit code diffs.
#git log#git show#History#Beginner
Back to all Git & GitHub Questions→