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 log
displays. 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 log
will 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 log
output 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 log
will 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
ls
command will list all of the files in the current directory. Thels
command has a-l
flag (i.e.ls -l
) that runs the samels
command but alters how it works; it now displays the information in thelong_format (the-l
for_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 log
command 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 --oneline
command and want to get out of thegit log --oneline
output and return to the regular command prompt. What do you press on the keyboard to return to the regular command prompt?
the
esc
keythe
q
keythe
ctrl
+c
keysthe
ctrl
+d
keys
SUBMIT
git log --oneline Recap
To recap, the--oneline
flag is used to alter howgit log
displays 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