git

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

sortable list of dates and hashes
%aI = ISO date, %h = commit hash

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

list 100 most recent commits, one per line, with YYYY-MM-DD dates
%h = commit hash, %x09 = space, %an = author name, %ad = commit date, %s = commit message

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

list commits that a merge (a PR) from dev into master would add to master
%h = commit hash, %x09 = space, %ad = commit date, %s = commit message, --date=short = yy-MM-dd

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

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

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

show parent branch

git rebase -i --root branchname

rewrite whole branch history

git rebase -i HEAD~2

rewrite history for last 2 commits

git branch -vv

show last commit & tracked remote

git reset --hard remoteName/branchName

reset hard to match remote

git show --name-only

show files in last commit

git log -- path/to/file.js

show commits that changed file

git show a1b2c3 path/to/file.js

show how a file changed in a commit

git config --global core.autocrlf input

convert to LF on check in (Mac / Linux)

gitgit config --global core.autocrlf true

convert to CRLF on check out (Windows)

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

change date of last commit to current date

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

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

git show branchName:path/to/file.txt > original.txt

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