Changing How Git Log Displays Information
You made it all this way - congrats on getting this far! Seriously! Learning Git is a challenging undertaking. I applaud you on your perseverance.
Take a look at this output from runninggit log:
The Terminal application showing the output from runninggit log.
We've been looking closely at all the detailed information thatgit logdisplays. But now, take a step back and look at all of the information as a whole.
Let's think about some of these questions:
- the SHA
git logwill display the complete SHA for every single commit. Each SHA is unique, so we don't really need to see the _entire _SHA. We could get by perfectly fine with knowing just the first 6-8 characters. Wouldn't it be great if we could save some space and show just the first 5 or so characters of the SHA?
- the author
- the
git logoutput displays the commit author for every single commit ! It could be different for other repositories that have multiple people collaborating together, but for this one, there's only one person making all of the commits, so the commit author will be identical for all of them. Do we need to see the author for each one? What if we wanted to hide that information?
- the
- the date
- By default,
git logwill display the date for each commit. But do we really care about the commit's date? Knowing the date might be important occasionally, but typically knowing the date isn't vitally important and can be ignored in a lot of cases. Is there a way we could hide that to save space?
- By default,
- the commit message
- this is one of the most important parts of a commit message...we usually always want to see this
What could we do here to not waste a lot of space and make the output smaller? We can use a flag.
TIP: This isn't a course on the command line, but a flag is used to alter how a program functions. For example, the
lscommand will list all of the files in the current directory. Thelscommand has a-lflag (i.e.ls -l) that runs the samelscommand but alters how it works; it now displays the information in thelong_format (the-lfor_long).Flags can be used to alter how a program functions and/or what is displayed. To learn more about command line programs and flags, check out our course Linux Command Line Basics.
git log --oneline
Thegit logcommand has a flag that can be used to alter how it displays the repository's information. That flag is--oneline:
$ git log --oneline
Check out how different the output is!
QUIZ QUESTION
You're deep in the weeds of thegit log --onelinecommand and want to get out of thegit log --onelineoutput and return to the regular command prompt. What do you press on the keyboard to return to the regular command prompt?
the
esckeythe
qkeythe
ctrl+ckeysthe
ctrl+dkeys
SUBMIT
git log --oneline Recap
To recap, the--onelineflag is used to alter howgit logdisplays information:
$ git log --oneline
This command:
- lists one commit per line
- shows the first 7 characters of the commit's SHA
- shows the commit's message
Two Terminal applications side-by-side. The left one shows the result of the