This article covers how to use the command 'Git Status' and 'Git Log'.
Git Status is a useful command for us to gather information about the branch we're currently working on:
For instance, if I run the command on this blog while I'm writing this article, I would get:
This command lets us gather information such as:
- If the branch we're on is up to date
- Any files that are staged, unstaged or untracked
- Any files that have been created, modified or deleted
- If there is anything to commit, pull or push
The status output doesn't show you any information about the commit history however. To do this, we need to use git log:
Whereas git status gave information about the current working directory, git log will display the commit history for your branch.
Again, if I run the command now on this blog I get the following:
In my instance, the output took up more than one screen. You can use space to scroll, and q to exit.
If you're working on a main branch, it's likely you've just requested thousands of pages of commit history. You can limit the amount of commits you get back using:
git log -n <limit>
You can also condense each commit to a single line, to get a good overview of the commit history:
git log --oneline
You may also wish to see the git log of one author, or many authors in particular:
git log --author="<author-or-regex>"
The string you pass into author can be either a plain string that matches all or part of the authors name or email address, or it can be a regular expression.
Finally, it can be useful to see the commit history of a specific file, particularly if a new issue has arisen:
git log <filename>
Combining this with the -p flag, you will return the most detailed view you can have of the project history, by displaying the full diff of each commit:
git log -p # For a single file git log -p <filename>