git snipets - ghdrako/doc_snipets GitHub Wiki

empty commit

At least two occasions where creating an empty commit can make quite a bit of sense:

  • Initializing new repositories.
  • Triggering continuous deployment pipelines.
git commit --allow-empty -m "Initial commit"

Output the latest commit message

git log -1 --format=%s
git show -s --format=%s
git show-branch --no-name HEAD # work much faster then above command !!!  
time git show-branch --no-name HEAD # show execution time

Flags:

  • The -1 in git log -n command refers to the latest commit.
  • The -s flag (or --no-patch) is optional. However, it is specified here to suppress the diff output — which is shown by the git show command by default in addition to the full commit details.

Format:

  • The %s in --format=<format> option refers to the "subject" line of the commit output.
  • the %h format modifier to also output the short hash of the commit (or %H for the full hash)

Find Git Commit ID by Commit Message

git log --grep="Updated"
git log --grep="Updated" -i              # case sensitice
git log --grep="Updated" --grep="readme" # logical or commit message matches at least one of the given patterns
git log --grep="Updated" --grep="readme" --all-match  # logical and

Flags

  • -i flag (or --regexp-ignore-case)
⚠️ **GitHub.com Fallback** ⚠️