Changing How Git Log Displays Information_10
2018-03-25 22:03 Weiweim 阅读(268) 评论(0) 编辑 收藏 举报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 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? - 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 the long 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
The git 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!
You're deep in the weeds of the git log --oneline
command and want to get out of the git log --oneline
output and return to the regular command prompt. What do you press on the keyboard to return to the regular command prompt?
Remember, the q
key gets out of the git log
view. We're still using git log
but are just passing a flag to change how the information is displayed. So the q
key still works and returns the terminal to the command prompt.
git log --oneline Recap
To recap, the --oneline
flag is used to alter how git 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
We just looked at the --oneline
flag to show one commit per line. That's great for getting an overview of the repository. But what if we want to dig in a little to see what file or files were changed by a commit?
This is one reason why a good, descriptive commit message is so important. But even with the commit message, we still don't know for sure what file or files were modified in this commit.
git log --stat
Intro
The git log
command has a flag that can be used to display the files that have been changed in the commit, as well as the number of lines that have been added or deleted. The flag is --stat
("stat" is short for "statistics"):
$ git log --stat
Run this command and check out what it displays.
git log --stat
Recap
To recap, the --stat
flag is used to alter how git log
displays information:
$ git log --stat
This command:
- displays the file(s) that have been modified
- displays the number of lines that have been added/removed
- displays a summary line with the total number of modified files and lines that have been added/removed
This article from Udacity