H/T Katacoda

It's Monday and what is a better day and time to refresh (and share) some useful Git commands.

Viewing commit logs

There is the useful git log, which is great for viewing commit logs along with the history of a repository.  With that said, there is an even better (ie., prettier) way to view a history of commits:

git log --pretty=format:"%h %an %ar - %s"

The output results in each commit being printed on a separate line via stdout. Nice!

To view changes in a commit run:

git show

# view an older commit
git show <commit-hash>

Creating a verbose commit

If you would like to create a commit that is a bit more verbose, here a a few steps to achieve this:

# create test directory
mkdir test-git && cd test-git

# initialize repo
git init

# Choose your editor of choice => I use Vim
git config core.editor 'vim'

# Verify editor of choice
git config core.editor

# create something new
vim hello-world.md

# add:
Hello world!

# add new file
git add hello-world.md

# Commit and create verbose message
git commit -v

# add a message
....a more verbose message....

# view commit with added message
git log

# or
git log --pretty=format:"%h %an %ar - %s"

That's it for now for this very brief post. I'm on to some work with Kubernetes for now.  

I will post more useful git commands in the future.

Happy Monday!