--format
- Git course
- Advanced
- Lesson 26/56
- 4 min
Learn custom output with git log --format.
git log --format
git log --format lets you customize how commit information appears in the terminal. Instead of using a predefined layout, you can choose fields such as commit hash, author, and message in your preferred order. This option is especially useful when preparing custom history reports.
git log --format="%h %an %s"Common Format Placeholders
Each placeholder in Git's custom formats represents different commit information. %H displays the full commit hash, %h the abbreviated hash, %an the author's name, and %s the commit subject. You can combine these placeholders to create single-line or detailed reports.
git log --format="%H | %an | %s"The order of the placeholders determines the order of the fields in the output.
Practice Create Custom Commit Output
Assign a command to command that displays the abbreviated hash, author name, and commit subject in that order. Separate the fields with the | character. Print the result.
Starter code
// Özel format komutunu oluştur
const command = "";
// Komutu yazdırSample solution
const command = 'git log --format="%h | %an | %s"';
console.log(command);Expected output
git log --format="%h | %an | %s"
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which placeholder displays the commit message in a custom format?
- %an
- %h
- %ad
- %s Correct answer
Explanation: <code>%s</code> displays the commit subject. <code>%an</code> shows the author's name, while <code>%h</code> shows the abbreviated commit hash.
2 Display the Author Name
git log --format="%h %an"____
git log --format="%h %an"%an
Explanation: The <code>%an</code> placeholder displays the name of the commit author.
3 Format Placeholders
| Term | Meaning |
|---|---|
%H |
Full commit hash |
%h |
Abbreviated commit hash |
%an |
Author name |
%s |
Commit subject |