Line history
- Git course
- Advanced
- Lesson 10/56
- 4 min
Learn to inspect the history of a specific line.
Inspecting line history
With git blame, you can see the latest modification information for lines in a file. When investigating a line, identifying its commit ID is important. You can use that ID to inspect the commit message, changed files, and actual changes.
git blame src/user.js
git show 7ab91cdBlame shows the commit that last modified a line; it does not necessarily identify when the line was first introduced.
The relationship between a line and a commit
A line's blame entry points to the commit that last changed its current content. For example, a line may have been added in an earlier commit and slightly edited in a later one. In that case, blame identifies the commit that made the latest edit.
git blame src/config.jsAfter obtaining the commit ID, use git show to inspect the change context and investigate why the line was updated.
Practice Use blame and show together
Display line attribution for src/payment.js. Then inspect the example commit c91de42 in detail.
Starter code
# Dosya satırlarının geçmişini göster
# Belirtilen commit'i inceleSample solution
git blame src/payment.js
git show c91de42Expected output
Blame information displayed for src/payment.js. Commit c91de42 details displayed.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 You want to inspect the commit ID shown beside a line in blame output. Which command is appropriate?
- git clone COMMIT_ID
- git switch COMMIT_ID
- git show COMMIT_ID Correct answer
- git init COMMIT_ID
Explanation: git show displays the message and changes made by the specified commit.
2 Display a line's commit details
git show ____
git show 7ab91cd
Explanation: A commit ID obtained from blame output can be inspected with git show.
3 Line history investigation
| Term | Meaning |
|---|---|
git blame |
Finds a line's last change record |
Commit kimliği |
Selects the commit to inspect |
git show |
Displays commit details |
Commit mesajı |
Explains the purpose of the change |