Tag

commanddescribe
git tag列出所有tag
git tag -l v1.*列出符合条件的tag(筛选作用)
git tag [tag_name]创建轻量tag(无-m标注信息)
git push REMOTE TAG推送一个tag到远端
git push origin –tags*推送所有本地tag到远程
git push origin :refs/tags/[REMOTE TAG]
git push –delete REMOTE TAG
删除远程指定tag
git fetch origin [remote_tag_name]拉取远程指定tag
git show [tag_name]显示指定tag详细信息
git push origin [local_tag_name]推送指定本地tag到远程
git tag NEW_TAG OLD_TAG
git tag -d OLD_TAG
重命名本地tag
git tag -d [local_tag_name]删除本地指定tag
git ls-remote –tags origin查询远程tags
git tag -a [tag_name]创建含注解的tag
git fetch origin [remote_tag_name]
git checkout [remote_tag_name]
git branch
checkout远端tag到本地

Checking

检查工作目录与暂存区的状态

commanddescribe
git status查看在你上次提交之后是否有对文件进行再次修改
git status -s获得简短的输出结果
git diff用于比较文件间差异
git diff –cached
git diff –staged
显示暂存区(已add但未commit文件)和最后一次commit(HEAD)之间的所有不相同文件的增删改
git diff HEAD工作目录(已track但未add文件)和暂存区(已add但未commit文件)与最后一次commit之间的的所有不相同文件的增删改
git diff <branch1> <branch2>                          比较两个分支上最后 commit 的内容的差别

Log

commanddescribe
git diff branch1 branch2 –stat 显示出所有有差异的文件(无内容)
git log <b1>..<b2>查看 b1 中的 log 比 b2 中的 log 多提交了哪些内容
git log –oneline以 <commit_id> <comment> 为一行来显示
git log -S <‘LoginViewController’>log 的输出将添加火删除对应字符串
git log –all –grep=<‘0117’>log 的输出将过滤出与对应字符串相关的commit

Checkout

checkout 是指不同tag或分支间的切换行为

commanddescribe
git checkout TAG切换至一个tag
git checkout -b BRANCH TAG创建一个新分支,并切换至这个tag
git checkout BRANCH切换至一个分支
git checkout -m BRANCH在切换分支时如有冲突则合并
git checkout COMMIT_HASH切换至一个commit
git checkout -b BRANCH HEAD~4
git checkout -b BRANCH COMMIT_HASH
切换并创建为新分支
git checkout COMMIT – FILE_PATH          将 FILE_PATH 指定的文件恢复为当前分支的最新版本(仅未add)

Remote

remote 子命令用于管理repositories

commanddescribe
git remoteList all remote
git remote rename OLD_REMOTE NEW_REMOTERename remote
git remote prune REMOTERemove stale remote tracking branches

Branch

branch 用于管理分支

commanddescribe
git branchList all branches
git checkout -b BRANCHCreate the branch on your local machine and switch in this branch
git branch BRANCH COMMIT_HASH    Create branch from commit
git push REMOTE BRANCHPush the branch to remote
git branch -m OLD_BRANCH NEW_BRANCH      Rename other branch
git branch -m NEW_BRANCHRename current branch
# Rename branch locally
git branch -m OLD_BRANCH NEW_BRANCH

# Delete the old branch
git push origin :OLD_BRANCH

# Push the new branch, set local branch to track the new remote
git push –set-upstream REMOTE NEW_BRANCH
Rename remote branch
git branch -D BRANCH
git push REMOTE :BRANCH
Delete a branch locally and remote
git branch | grep -v “master” | xargs git branch -DDelete all local branches but master

Commit

Record changes to the repository

commanddescribe
git reset –hard HEAD~1Undo last commit
git rebase -i HEAD~5
git reset –soft HEAD~5
git add .
git commit -m “Update”
git push -f origin master
Squash last n commits into one commit
git branch newbranch

# Go back 3 commits. You will lose uncommitted work.1
git reset –hard HEAD~3

git checkout newbranch
Move last commits into new branch:
git rebase -i HEAD^^^
git add .
git rebase –continue
Make changes to older commit

Merge

Join two or more development histories together

commanddescribe
git checkout BRANCH
git merge –no-ff BASE_BRANCH
Merge commits from master into feature branch
git merge BRANCHCurrent branch merge to BRANCH branch
git merge -m “Merge from Dev”When merge branch add comment
git merge -s ours obsoleteMerge obsolete branch to current branch using ours policy
git merge –no-commit maintMerge maint branch to current, than do not make new comment

Cherry Pick

Apply the changes introduced by some existing commits

bash
1
git cherry-pick COMMIT_HASH_A COMMIT_HASH_B

Revert

commanddescribe
git revert HEADRevert the previous commit
git revert –no-commit HEAD~3..Revert the changes from previous 3 commits without making commit

Amend

commanddescribe
git commit –amendAmend previous commit
git commit –amend –no-edit
git commit –amend -m “COMMIT_MESSAGE”Changing git commit message
git commit –amend -m “COMMIT_MESSAGE”
git push –force REMOTE BRANCH
Changing git commit message after push

Reflog

reference log

commanddescribe
git reflogShow reflog
Get commit

Rebase

Rebase the current branch onto another branch

commanddescribe
git rebase BASE_BRANCHRebase the current branch onto another branch
git rebase –continueContinue rebase
git rebase –abortAbort rebase

Tracking

commanddescribe
git cleanRemove untracked files
git reset FILE_PATHRemove file from index
git resetReset the index to match the most recent commit
git reset –hardReset the index and the working directory to match the most recent commit
git rm fileRemove files from the working tree and from the index
git ls-filesShow information about files in the index and the working tree
git ls-files -dShow deleted files in the output.
git ls-files -mShow modified files in the output.
git ls-files -iShow only ignored files in the output.
git ls-files –no-empty-directoryDo not list empty directories. Has no effect without –directory.

Config

commanddescribe
git config -llist all git config
git config –global [key] “[value]”set global configuation
git config [key] “[value]”set current repositories configuation

Reference

awesome-git-commands