Notes on Git log, diff and show

Sadhana Jaiswal
4 min readSep 6, 2020

--

Git is a version control system used by wide range of software developers. It includes many command to do the thing. Here, we focus on log, diff and show commands and I am hoping you already have basic experience with github and git commands. If not then check some tutorial for git beginner level.

In this post, We learn many effective way are using these.

Magical part of Git Log

  • git log

It shows commit history with all details. By default this command displays the commit SHA, author, date and message.

To scroll through the commit messages press up arrow to move up and q to quit out of the log.

  • — oneline

This command lists one commit per line. This we use when we just want to look on only commit message and SHA.

git log --oneline

Shows the first 7 characters of the commit SHA and the commit message and nothing more.

  • — stat

This command shows each commit in more details.

  1. show number of files have been modified, number of lines have been added or removed.
  2. along with author name, date, commit message
git log --stat
  • -p / — patch

This displays following info..

  1. The files that have been modified,
  2. Location of the lines that have been added or removed and the actual changes that have been made.
  3. along with author name, date, commit message
git log -p
or
git log --patch

It actually shows the code and place where the changes happened.

  • — graph

Draw a text-based graphical representation of the commit history on the left hand side of the output. This graph shows not only the commits (as asterisks *) but also their “parent” commits.

git log --graph

— graph, mostly use in case of checking merge flow and branch or commit in commit history. There are may other options you could use in combination with --graph. Couple of them are --decorate and --all. Try out with --graph.

Git Diff

  • — diff

Diff command is used in git to track the difference between the changes made on a file. Diff command takes two commit id (SHA) and reflects the differences between them.

git --diff <old commit> <new commit>
  • — difftool

This is a Git command that allows you to compare and edit files between revisions using common diff tools(like beyond compare editor or similar). You should have any comparison tool when use “git difftool”

git --difftool  <old commit> <new commit>

Git Show

  • show

git-show is a command line utility that is used to view expanded details on Git objects such as blobs, trees, tags, and commits. git-show has specific behavior per object type.

  1. Tags show the tag message and other objects included in the tag.
  2. Trees show the names and content of objects in a tree.
  3. Blobs show the direct content of the blob.
  4. Commits show a commit log message and a diff output of the changes in the commit.
git show
git show HEAD
git show <commit>
...

Tricks with git log

  • filter commit by author name
git log --author="sadhana"
  • filter commit by date
git log --after="2020-15-05"git log --after="2020-15-05" --before="2020-25-05"git log --after="yesterday" // shows only commits from yesterdaygit log --after="today" // shows only today commits git log --before="10 day ago" // omits last 10 days commits git log --after="1 week ago" //show only commits from last week git log --after="2 week ago" git log --after="2 month ago" // shows only last 2 months commits
  • filter commit by log message
git log --grep="fix calculation"
  • show only merge commit
git log --merges
  • filter commit by files
git log main.py

These are the basic level but strong things to know. It often require to use in our workplace and make our work easy. Finding any commit details or checking difference between two commit or files.

Hope this have help to you.

Thank you for reading :)

--

--