Git - sirdnt/quintessence GitHub Wiki
global
git config --list
git config --global user.name "Name"
git config --global user.email "[email protected]"
git config --get remote.origin.url
git ignore global
git config --global core.excludesfile ~/.gitignore_global
local repository only
git config user.name "name"
git config user.email "[email protected]"
git checkout <branch>
checkout to a branch with it name
git checkout -b <branch>
checkout create new branch with current change
Checkout remote branch with specific local branch
git checkout -b test origin/test
Check tracking branch of current branch
git branch -vv
Rename branch
on current branch : git branch -m
on other branch: git branch -m
git commit -m "commit message"
Amend commit
git commit --amend -m (optional)
Push local change to new remote branch
git push -u
git push --set-upstream origin //push local branch to remote
Check branchs haven't merged
git branch -r --no-merged origin/
Merge branch to current branch
git merge <branch name>
git diff --param SHA1 SHA2
show only diff file from two commits with file name only
git diff --name-only SHA1 SHA2
git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short
git log --pretty=format:'%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s'
More info here
git diff --shortstat //show diff stat code not commit yet
git diff --shortstat SHA1 SHA2
git diff --shortstat 7b96fcf f25cdf2
git log --shortstat --oneline //stat show when log
check branchs haven't merged
git branch -r --no-merged <branch name> //local branch
git branch -r --no-merged origin/<branch name> //remote branch
Case branches deleted on remote but still exist on local
git remote prune origin (will remove all such stale branches)
git rm -r --cached .
git add .
git commit -am "Remove should ignore files"
Reset local branch with remote branch
git reset --hard origin/<remote branch>
Reset to a commit
git reset --hard <commig hash>
Undo last commit and recommit again
git reset --soft HEAD~1
git commit -m "message"
If pushed to remote
git push -f //force push rewrite origin branch
Reset param: --soft,--mixed,--hard
- --mixed (default): uncommit + unstage changes, changes are left in working tree.
- --hard: uncommit + unstage + delete changes, nothing left.
- --soft: uncommit changes, changes are left staged (index).