avatar Deluxe Blog Tips About Projects

Some useful and frequently used Git log commands

I usually use Git log commands to check changes in my plugins and themes. While some app like SourceTree does that job very well, I prefer command lines in some situations. Here are some git log commands that I use quite a lot.

Common Git Log Commands

1. Show list of commits

git log --graph --oneline

If you use zsh, you can simply use

glol

2. Show only file names in commits

git log --graph --oneline --name-only

3. Show full commits

git log -p

If you use zsh, you can use

glgp

4. Show git log of a specific commit

git show ac29810

Sometimes, it's hard to copy the commit reference. So you might want to use relative reference. Here are some tips:

Just use:

  • HEAD^ to get the second last commit
  • HEAD^^ to get the third last commit on branch master.
  • HEAD~10 to get the 10th last commit

They can even be combined: HEAD^^~5^.

HEAD can be any branch name (local or remote). You might also want to use code>@</code instead of HEAD which give the same result.

5. Show the change history of a file

git log --graph --oneline [filename]

6. Show change of a file in a specific commit

git show ac29810 [filename

Beautiful Git Log

I remember when I used to use zsh that has a Git plugin. The plugin has some Git aliases that show the log beautifully. So, I decided to do the similar thing with git log only. And I found this post and this post. So I decided to make a combination of them:

Just run these commands below to add 2 git aliases:

git config --global alias.l "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
git config --global alias.ls "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --all --find-copies -M --stat

And here is what you have:

Output of git l:

Output of

Output of git ls:

Output of

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Comments