git command
commands
get head commit id
view remote repo
git remote -v
git remote set-url origin git@github.com:fanqingsong/vanna-flask.git
git remote set-url --push origin git@github.com:fanqingsong/vanna-flask.git
git remote show origin
git branch -r
local branches
git branch
git checkout -b xxx
alias
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
example:
git config --global alias.unstage 'reset HEAD'
git unstage test.py
git reset HEAD test.py
add tag
push tag
git push origin --tags
git push origin tagname
push to origin
git push origin master:refs/for/master
git push origin HEAD:refs/drafts/master
git push origin master:refs/heads/master
git push review
git remote add review https://xxxx
git config remote.review.pushurl https://xxx
git config remote.review.push 'HEAD:refs/drafts/master'
push head to origin master or dev
git push origin master
git push origin dev
drop all your work
git reset --hard origin/master
git reset --soft origin/master
git add all but exclude some one file
git add -u
git reset -- static/js/dashboard.js
stash all your work
pop out your stash
git stash pop
git stash apply xxx
git stash drop xxx
git patch
git diff > patch
git diff HEAD HEAD^ > patch
git format-patch HEAD^
git format-patch commit_new commit_old
git apply patch
git apply --check patch
remove the HEAD commit
git reset --hard HEAD^
git reset --hard HEAD~100
git reset --hard 3628164
remove the HEAD commit softly, all change will be in stage
get logs
git log --graph --pretty=oneline --abbrev-commit
get the deleted commits log, it is helpful to restore them if you use git reset --hard wrongly
set head to the specified commit
git reset --hard commit_id
revert the specified commit
merge commit into this branch from other branches
git cherry-pick 00940ac970b9ddab63bff928479668bbfa293aaf
git cherry-pick commit1..commit100
merge one file into this branch from other branches
git checkout feature/new1.1 -- usercontroller.php
create new branch
git checkout -b mywork origin
create new branch with remote branch
git checkout -b dev origin/dev
switch branch
delete branch
git branch -d feature-discuss
// 删除本地分支
git branch -d localBranchName
// 删除远程分支
git push origin --delete remoteBranchName
rebase current branch on origin branch
merge another branch with this branch, will generate a merge commit on top
merge another branch with this branch without fast forward
git merge --no-ff another_branch
show diff
git diff
git diff HEAD HEAD^
git diff HEAD HEAD^ --name-only
git show HEAD --name-only
git diff readme.txt
position who make revision
add tag
git tag <tagname>
# Git will create a tag at the current revision but will not prompt you for an annotation. It will be tagged without a message (this is a lightweight tag).
git tag -a <tagname>
# Git will prompt you for an annotation unless you have also used the -m flag to provide a message.
git tag -a -m <msg> <tagname>
# Git will tag the commit and annotate it with the provided message.
git tag -m <msg> <tagname>
# Git will behave as if you passed the -a flag for annotation and use the provided message.
delete tag
config
git config --global user.email "qsfan@qq.com"
git config --global user.user "fanqingsong"
git config --global credential.helper store
git config --global credential.helper
git config --unset credential.helper
git credential-store clean
update locally
git pull origin next
==
git fetch origin master
git merge FETCH_HEAD