This page likely won't work without JavaScript enabled.git snippets

git snippets

sortable list of dates and hashes

git log --format="%aI%h"

%aI = ISO date, %h = commit hash

list 100 most recent commits, one per line, with YYYY-MM-DD dates

git log -n 100 --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short

%h = commit hash, %x09 = space, %an = author name, %ad = commit date, %s = commit message

list commits that a merge (a PR) from `dev` into `master` would add to `master`

git checkout master git log ..dev --pretty=format:"%h%x09%ad%x09%s" --date=short

%h = commit hash, %x09 = space, %ad = commit date, %s = commit message, --date=short = yy-MM-dd

list files changed in a commit. in the first command, the commit hash is optional and defaults to the last commit.

git show --pretty="" --name-only abc123 git diff-tree --no-commit-id --name-only -r abc123

show parent branch

git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//'

rewrite whole branch history

git rebase -i --root branchname

rewrite history for last 2 commits

git rebase -i HEAD~2

show last commit & tracked remote

git branch -vv

reset hard to match remote

git reset --hard remoteName/branchName

show files in last commit

git show --name-only

show commits that changed file

git log -- path/to/file.js

show how a file changed in a commit

git show a1b2c3 path/to/file.js

convert to LF on check in (Mac / Linux)

git config --global core.autocrlf input

convert to CRLF on check out (Windows)

git config --global core.autocrlf true

change date of last commit to current date

COMMIT_DATE="$(date)" git commit --amend --no-edit --date "$(date)"

change date of last commit to Mon 20 Aug 2018 20:19:19 BST

COMMIT_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST"

grab file.txt from branchName and save it as original.txt on the current branch

git show branchName:path/to/file.txt > original.txt COMMIT_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST"