
config
git config --global user.name
, 设置提交用户的名称git config --global user.email
, 设置提交用户的邮箱地址
init
git init
,将当前目录初始化为一个仓库
clone
git clone --bare <URL>
, 克隆一个裸仓库git clone -b <URL>
, 下载指定分支代码git clone --depth=n <URL>
, 浅克隆, n为大于0的整数,表示克隆深度
add
git add <file>
, 将文件添加到暂存区
status
git status
, 查看当前工作目录跟暂存区,本地仓库的关系
diff
git diff <file>
, 查看工作区文件与暂存区文件的差别
commit
git commit -m "demo"
, 将暂存区文件提交到本地仓库
reset
git reset
, 回退上一步的操作git reset --hard <commit>
, 将工作区设置为某次提交
rm
git rm <file>
, 删除某个文件并提交到暂存区
branch
git branch
, 查看本地分支git branch -d <branch>
, 删除本地分支git branch -D <branch>
, 相当于git branch -d <branch> -f
git branch -r
, 显示远端分支git branch --set-upstream-to=<upstream> <branch>
, 将本地分支与远端分支关联
checkout
git checkout <branch>
, 切换到某个分支git checkout -b <branch>
, 创建新的分支并切换到该分支
merge
git merge --no-commit <commit>
, 将某一次提交以及之前的提交合并到当前分支git merge <branch>
, 将指定分支合并到当前分支
log
git log -n
, 查看n条日志git log --after="2020-05-27"
, 查看指定日期之后的日志git log --before="2020-05-27"
, 查看指定日期之前的日志git log --author="author"
, 查看指定作者的日志git log --merges
, 查看merge的日志
stash
git stash
, 将提交到暂存区的进行存储git stash list
, 列出已经创建的存储git stash show <stash>
, 显示某个存储具体信息git stash pop <stash>
, 恢复到某次存储git stash clear
, 清除所有存储
tag
git tag <tagName> <commit>
, 根据commitID创建一个taggit tag -m "message" <tagName> <commit>
, 创建一个备注信息为message的taggit tag --list
, 列出已有taggit tag -d <tagname>
, 删除指定tag
fetch
git fetch origin master
, 将远端分支更新到本地仓库
pull
git pull
, 更新工作区的代码
push
git push origin master
, 将当前分支推送到master分支git push --tags
, 将本地标签推送到远端git push origin master -f
, 强制推送
remote
git remote -v
, 显示本地仓库对应的远端地址git remote add origin <url>
, 添加远端地址git remote remove origin
, 删除origin对应的远端地址git remote rename origin old-origin
, 将origin重命名为old-origin
cherry-pick
git cherry-pick <commit>
, 将某次提交合并到当前分支
revert
git revert <commit>
, 回退某次提交