Commit history in git

Git repository can be considered as a chain of commits as shown in below image. In below image, C1 is the first commit. C2 is the second commit. C2 will point to C1. If we add on more commit say C3, C3 will point to C2. There is special pointer called as HEAD which always points to the currently checked out commit. If you want to view the history of Git commits, you can use below command.
git log

Below image shows that current branch of the repository has 2 commits. For each commit, it shows below information.
  • Commit hash id
  • Author of the commit
  • Time stamp when the commit was made
  • Commit message

git log options

git log command accepts lot of parameters as mentioned below.
  • git log -3 : This shows only last 3 commits
  • git log –author=”sagar” : This shows only commits made by specific author say sagar
  • git log –after=”2016-06-12 14:37″ –before=”2016-06-12 15:59″ : This shows commits made only between 12 June 2016 14:37 to 12 June 2016 15:59
  • git log –all –grep “[abc|xyz]” : shows all commits where commit message matches the given regular expression.
  • git log –graph –oneline –decorate –all : shows git history in graphical format
  • git log –pretty=oneline : Shows git history in one line per commit
  • git log –name-status : shows which files have changed in each commit
  • git show –pretty=”format:” –name-only 878sdjhsk8 : shows which files have changed in git in specific commit
Complex problems, Simple Solutions