How to view commit history with Git Log - CloudSavvy IT
Web agency » Digital news » How to view commit history with Git Log -

How to view commit history with Git Log -

Git tracks commits over time, allowing you to track your code's progress and history. While you can still use Github online to view the public repository, browsing your local repository requires the use of CLI tools to view Git commit history, such as git log.

The CLI-free solution: just use a Git client

While you definitely need to learn how to use Git from the command line, as it helps understand everything you're doing, this is one of the few times when it really makes more sense to have a proper interface for you. view Git history, especially when considering multiple branches, remotes, tags, and contributors. The experience of using online services like GitHub is clearly beneficial, so why not have it on the desktop?

There are many Git GUI clients out there, but the most notable are Github Desktop, GitKraken, Fork, and SourceTree.

However, it is still helpful to learn the commands. You might not want to use a GUI, or you might be in a remote environment via SSH, or you might just want to take a look while you're already on your terminal. Fortunately, using git log is pretty easy.

Use git log

By default, git log shows a lot of information about each commit - ref ID, author, date, commit message and if this is the HEAD of all branches.

gitlog

If you want to know which files are affected, you will have to run it with --stat, which will display a list of files with additions and deletions.

git log --stat

If you want to know what really changed in these commits, you will have to run it with -p, which can be used with or without --stat:

git log --stat -p

This can be a lot to filter out, so you can sort by date:

git log --after = "2014-7-1" --before = "2014-7-4"

Or display by file concerned:

git log - example.json

Or with a search string:

git log -S "Hello, World!"

Or view important merge commits:

git log --merges

And, if you just want to view the changes of a single commit from the log, you can copy the hash and run git show:

git show e9d802bdc3a61943b2c9c736194a202b4e000180

Viewing branch history

Just having a list of commits can be tricky to sort branches. Fortunately git log provides the --graph option that can be used with some

git log --graph --oneline --decorate

You can also use custom formatting if you don't like the look of this:

--pretty = format: "% cn committed% h on% cd"

This particular set of parameters is very useful, but there is no shortcut for it, so if you use it a lot, we recommend that you define an alias in ~/.bashrc, or any equivalent configuration you use for your shell:

alias gitgraph = "git log --graph --oneline --decorate"

★ ★ ★ ★ ★