init
git init
add remote url
git remote add origin repo-url
delete remote url
git remote rm origin
clone from remote
git clone repo-url
check status
git status
add all changes
git add . #add all file in current folder
git add -A #git
add some file
git add file-path
commit to repo
git commit -m 'comment'
remove all commits not in origin/master
git reset --hard origin/master
push to remote
git push
log
git log #查看最近 提交
git log -10 #查看最近 提交 -10
git log --graph #查看最近 提交 --graph
gitk #GUI查看提交记录,需要用homebrew 升级git
gitk file-path #GUI查看filefile-path提交记录
git log --decorate
git log --decorate --all --oneline --graph
checkout
git checkout .
git checkout <commit number> <filename> #**常用**
git checkout 3f33b7959ff97715d69e418620895d98b811f8cb folder-name/* #恢复某folder-name下所有文件到 3f33b7959ff97715d69e418620895d98b811f8cb
撤销提交
git revert
view branches
git branch #查看本地分支
git branch -a #查看本地和服务器分支
create new branch
git branch new-branch-name
switch branch
git checkout branch-name #切换到branch-name
git merge from dev to master
git checkout master
git merge dev
delete branch
git branch -D branch-name #删除本地分支branch-name
git push origin --delete branch-name #删除服务器分支branch-name
基于远程跟踪分支创建本地分支
git checkout --track -b branch-name-on-local origin/branch-name-on-server
diff
git diff master origin/master # 比较 master(本地) 和服务器 master 的差异
push to server
git push origin branch-name-on-server
tag
git tag #查看所有标签
git tag v0.1.2-light #创建轻量标签
git tag -a v0.1.2 -m “0.1.2版本” #创建附注标签
git checkout tag-name
git tag -d v0.1.2 #删除标签
git tag -a v0.1.1 9fbc3d0 #补打标签
git push --tags
通常的git push不会将标签对象提交到git服务器,我们需要进行显式的操作:
git push origin tag-name #将tag-name标签提交到git服务器
git push origin –tags #将本地所有标签一次性提交到git服务器
push all
git push --all #push 所有branch
git push --all origin #push 所有tag 和所有branch到服务器