DEV Community

loading...
Cover image for git cake: when is my README’s birthday?

git cake: when is my README’s birthday?

bhupesh profile image Bhupesh Varshney 👾 Originally published at bhupesh-v.github.io on ・2 min read

Do you want to know when was a file/directory committed in your git history? Well here is git log at your rescue

git log --date=format:'%d %b %Y' --diff-filter=A --name-only --pretty='%n%C(yellow bold)🎂️ %ad%Creset by (%C(blue bold)%h%Creset)'

Enter fullscreen mode Exit fullscreen mode

git-cake-demo-paager

Ok ok! Let me explain for you lazy asses

  • --date=format:'%d %b %Y'

This is pretty much self-explanatory, suit this to your own preferred date format.

  • --diff-filter=A --name-only

This lets you filter nodes that were Added(A). Other filters include: Copied(C), Deleted(D), Modified(M) or Renamed(R). Multiple filters can be used together e.g --diff-filter=AC.

The --name-only shows only names of changed files. If you had like to print some status as well use --name-status

  • --pretty='%n%C(yellow bold)🎂️ %ad%Creset by (%C(blue bold)%h%Creset)

This is the beauty that is responsible for the line 🎂️ 18 Jun 2019 by (f72312c).

Git provides us with various format specifiers these include.

  • %n : newline
  • %h : abbreviated commit hash (short version, use %H for complete hash)
  • %ad : author date that respects the previously specified –date= option

Read git pretty docs for info. on all 50+ options

When you feel you are absolutely free do a git log --help & read that manual.

You should add this in your .gitconfig.

[user]
    email = varshneybhupesh@gmail.com
    name = Bhupesh-V
[commit]
    template = /home/bhupesh/.gitmessage
[core]
    editor = nano
[credential]
    helper = store
[alias]
        cake = log --date=format:'%d %b %Y' --diff-filter=A --name-only --pretty='%n%C(yellow bold)🎂️ %ad%Creset by (%C(blue bold)%h%Creset)'

Enter fullscreen mode Exit fullscreen mode

Now send me some presents, will ya? Please?

Seems interesting?, Subscribe 🚀 to read more such cool stuff or just connect with me on Twitter.

Discussion (2)

pic
Editor guide
Collapse
rokokorag profile image
Rodrigo Acevedo

Thanks! I added the author information:

-> %C(magenta bold)%an (%ae)%Creset
Enter fullscreen mode Exit fullscreen mode

The final command is:

git log --date=format:'%d %b %Y' --diff-filter=A --name-only --pretty='%n%C(yellow bold)🎂️ %ad%Creset by (%C(blue bold)%h%Creset) -> %C(magenta bold)%an (%ae)%Creset'
Enter fullscreen mode Exit fullscreen mode
Collapse
bhupesh profile image
Bhupesh Varshney 👾 Author

Nice, now the author is responsible for a treat 🍩