git init /path/
git rm/mv #rm/mv + track
git clean -fd #delete all untracked stuff
git rm -r --cached files #untrack files
Restore Files…
git checkout *sha* -- *files* #restore files from commit
git restore -p #interactive restoring files
git checkout-index files #restore from index
Compare …
git diff *one* *two* #compare file, branch, commits, etc.
git diff HEAD # wkdir , --staged for index
Actions on files/folders …
git diff --name-only HEAD~1 #files changed by recent commit
git ls-tree -r HEAD~2 #get sha & file/folders in it
git ls-files #list tracked files recursively
git ls-files -s folder
git status --ignored #see untracked files
Get details
git show obj #details
git hash-object file #show sha-1
git blame app.js #see latest changes + author
Git Log — browse history
git log [>> dev.log] #display
git shortlog [-n][--reverse] #only msgs [sort options]
git reflog #includes changes to HEAD pointer
Flags for git log
--grep="steel" #commits string
-4 #display last 4 commits
--before="yesterday" --after="2023-04-15"
--author="John|Mary"
--follow <files>
--stat #stats for each file
-S"hello" #commits which added hello to any file
-G"hello" #regex
--show-notes #also display author notes
--no-merges #avoid merge-commits
--merges #show only merge-commits
Git stash — save current working directory
git stash [push -m "msg"] #save
git list, clear, apply, drop, pop (apply+rm)
git stash pop stash@{2}
Git tags
git tag --list v1.*
git tag -a `v1.0` HEAD #Create light tag
git tag v1.2.2 -m `Release version 1.2.2` #good tag
Git Notes — Only 1 note is allowed per commit.
# default : HEAD
git notes add/append <c> -m "Mynote"
git notes show edit remove <c>
git notes copy [-f] <From> <To> #use -f to overwrite