git diff |
WORKSPACE vs STAGED
|
git diff --staged (or --cached) |
STAGED vs COMMITED
|
git diff HEAD |
WORKSPACE + STAGED vs COMMITED
|
git diff <SHA-1> |
WORKSPACE vs any commit (more general case of the above)
|
git diff master...topic |
Changes introduced if topic gets merged into master
|
-w |
IGNORE whitespace
|
git rm README |
Remove file from git and locally
|
git rm --cached README |
Remove file from git, but keep locally as UNTRACKED
|
git reset HEAD README |
UNSTAGE a file
|
git checkout -- README |
Revert a file back to its form from the last commit
|
git stash |
Push all TRACKED modified files (
-u to include untracked, -a to include ignored) |
git stash list |
LIST all stashes
|
git stash apply |
APPLY the last stash
|
git stash apply stash@{2} |
APPLY a chosen stash
|
git stash pop |
APPLY stash and DELETE it
|
git stash drop |
DELETE stash
|
git remote -v |
LIST remotes with URLs
|
git remote show <origin> |
GET details with tracked branches
|
git remote add <origin> <url> |
ADD a remote
|
git remote rename <origin> <upstream> |
RENAME remote origin to upstream
|
git remote rm <origin> |
DELETE remote
|
git push <origin> --delete <feature/one> |
DELETE branch from remote
|
git fetch origin |
FETCH all data from origin
|
git pull |
FETCH and MERGE
|
git push <origin> <master> |
PUSH branch to a remote
|
git branch -vv |
Details of local branches and what they track
|
git tag |
LIST tags
|
|
`-l "119.*"
|
FILTER tags
|
git tag -a v2.0 -m "Version 2.0" |
CREATE annotated tag
|
git tag v2.0 |
CREATE lightweight tag
|
git show v2.0 |
GET tag
|
git tag -d v2.0 |
DELETE tag
|
git push <origin> <tag> |
PUSH single tag
|
git push <origin> --tags |
PUSH all tags
|
git rebase master |
Takes commits from current branch and applies them on top of master. Master stays on previous commit, only current branch is moved
|
-p |
See differences in each commit
|
-2 |
Only 2 last commits
|
master feature/one |
Only commits between master and feature/one
|
--all |
Commits from all branches
|
--stat |
See file change statistics
|
--pretty=oneline/short/full/fuller/format:{some format} |
Formatting of output
|
--oneline |
Shorthand for
--pretty=oneline |
--graph |
Shows graph
|
--since=2.weeks/2010-01-15 (or after) |
Commits from
|
--until=2021 (or before) |
Commits to
|
--author=Joe |
Only by some author, can be used multiple times
|
--grep=word |
Filter by message content
|
-S word |
Filter by commit that changed occurence of
word in code |
git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" \
--before="2008-11-01" --no-merges
--pretty=format options
/etc/gitconfig (--system)~/.gitconfig (--global).git/config (--local)git config --global user.name "John Doe"git config --global user.email johndoe@example.comgit config --global core.editor codegit config user.namegit config --list --show-originCheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.