Log and History
Show helpful guides that come with Git
git help -g
Search change by content
git log -S'<a term in the source>'
Show changes over time for specific file
git log -p <file_name>
List all the conflicted files
git diff --name-only --diff-filter=U
List of all files changed in a commit
git diff-tree --no-commit-id --name-only -r <commit-ish>
Unstaged changes since last commit
git diff
Changes staged for commit
git diff --cached
Alternatives:
git diff --staged
Show both staged and unstaged changes
git diff HEAD
What changed since two weeks?
git log --no-merges --raw --since='2 weeks ago'
Alternatives:
git whatchanged --since='2 weeks ago'
See all commits made since forking from master
git log --no-merges --stat --reverse master..
Show all tracked files
git ls-files -t
Show all untracked files
git ls-files --others
Show all ignored files
git ls-files --others -i --exclude-standard
Visualize the version tree.
git log --pretty=oneline --graph --decorate --all
Alternatives:
gitk --all
git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'
Visualize the tree including commits that are only referenced from reflogs
git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)
Show inline word diff.
git diff --word-diff
Show changes using common diff tools.
git difftool [-t <tool>] <commit1> <commit2> <path>
Commits in Branch1 that are not in Branch2
git log Branch1 ^Branch2
List n last commits
git log -<n>
Alternatives:
git log -n <n>
Open all conflicted files in an editor.
git diff --name-only | uniq | xargs $EDITOR
View the GPG signatures in the commit log
git log --show-signature
Extract file from another branch.
git show <branch_name>:<file_name>
List only the root and merge commits.
git log --first-parent
List commits and changes to a specific file (even through renaming)
git log --follow -p -- <file_path>
Search Commit log across all branches for given text
git log --all --grep='<given-text>'
Get first commit in a branch (from master)
git log --oneline master..<branch-name> | tail -1
Alternatives:
git log --reverse master..<branch-name> | head -6
Show the author, time and last revision made to each line of a given file
git blame <file-name>
Show how many lines does an author contribute
git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s
", add, subs, loc }' -
Alternatives:
git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s
", add, subs, loc }' - # on Mac OSX
Show all the git-notes
git log --show-notes='*'
List unpushed git commits
git log --branches --not --remotes
Alternatives:
git log @{u}..
git cherry -v
Add everything, but whitespace changes
git diff --ignore-all-space | git apply --cached
blame on certain range
git blame -L <start>,<end>
Show a Git logical variable.
git var -l | <variable>
Get the repo name.
git rev-parse --show-toplevel
logs between date range
git log --since='FEB 1 2017' --until='FEB 14 2017'
Exclude author from logs
git log --perl-regexp --author='^((?!excluded-author-regex).*)$'
View expanded details of changes in last commit
git show
Visualize each position of HEAD in the last 30 days
git reflog