Video in progress

Junior 🌿 Git

Which variants of `git log` do you use to view commit history comfortably in the terminal?

In daily work, git log --oneline --graph --decorate is what I need most: each commit on one line, the branch lines, and where each branch points. For filtering you add --author, --since and a file path.

📖 Answer

Plain git log takes up too much room. I usually use these:

git log --oneline --graph --decorate --all   # the whole tree
git log --oneline -10                        # the last 10
git log --author="Aziz" --since="2 weeks ago"
git log -- src/main/java/uz/app/PaymentService.java  # history of just this file
git log -p -1                                # the last commit with its diff
git log -S "calculateFee"                    # commits that added/removed this string

-S (the pickaxe) is little known but very useful: it finds when a method appeared or was removed.

To avoid typing a long command every time, you can set an alias: git config --global alias.lg "log --oneline --graph --decorate --all".