Skip to content

Instantly share code, notes, and snippets.

@dedurus
Last active February 24, 2024 11:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dedurus/545feef2da4adf91e60525edec11e375 to your computer and use it in GitHub Desktop.
Save dedurus/545feef2da4adf91e60525edec11e375 to your computer and use it in GitHub Desktop.

Logging

Similar to git log, including list of files changed in each commit and hashes and status

git whatchanged

Listing files changed by commit including current status

git log --name-status

Lists only changed files by commit

git log -p --name-only

One-line Tree

git log --graph --decorate --pretty=oneline --abbrev-commit

Tree with custom format
  • %h abbreviated commit hash
  • %an author name
  • %cr committer date, relative
  • %s subject

git log --graph --decorate --pretty=format:%h [%cr] %s

Get own commit in a branch

git log --graph [branchname]

Search logs for specific code changes

git log --search=""

Show log only for specific author(s)

git log --author=""

Filter log using search term or regex

git log --grep=""

Show all commits between two references

git log ..

Show all commits made only to a specific file

git log --

diff Compare

Show only names of changed files

Compare the current branch against master branch

git diff --name-only master (shorter: git diff --name-only master)

Compare any two branches

git diff --name-only firstBranchName..secondBranchName

Show names and status of changed files

Compare the current branch against master branch

git diff --name-status master (shorter: git diff --name-status master)

Compare any two branches

git diff --name-status firstBranchName..secondBranchName

diffing 2 branches with stats

git diff --stat --color firstBranchName..secondBranchName

Generate a diff file from two branches

git diff firstBranchName..secondBranchName > myDiffFile.diff

Diff branches with a graph

git log --graph --left-right --cherry-pick --oneline firstBranchName...secondBranchName

Compare a file in 2 branches

git diff mybranch..master -- myfile.js

MISC

Previewing a file in another branch, without switching branches

git show branch:file

Add extra information to a commit without changing the commit message or modifying the history of the commit

git notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment