
虽然每天都在用Git命令,但是偶尔会出现某个不常用的命令记不起来,好尴尬呀。这次将Git命令再做一次总结。
branch分支
git branch 查看所有分支

image.png
git branch xx 创建分支

image.png
git checkout xx 切换分支

image.png
git branch -a 查看本地和远程所有分支

image.png
远程仓库
git push origin 分支名:分支名 推送本地分支名到远程

image.png
git fetch origin 分支名:分支名 拉取远程分支
git branch -r 查看远程分支

image.png
git branch -d 分支名 删除本地分支

image.png
git push origin --delete 分支名 删除远程分支

image.png
提交代码
git status 查看本地代码状态

image.png
git add file-name 添加某个文件
git add . 添加所有文件到暂缓区
git commit -a -m 'xxx' 提交代码备注xxx
git push origin 分支名 推送代码到远程分支

image.png
Git Tag
添加注解,比如产品发布一个版本打一个tag。
git tag -a tag-name -m "xxx" 创建tag

image.png
git push origin tag-name 推送tag到远程

image.png
git show tag-name 查看某个tag标记内容

image.png
git checkout tag-name 切换tag
git tag -d tag-name 删除本地tag

image.png
git push origin :refs/tags/tag-name 删除远程标签

image.png
其他操作
git stash 保存没有提交的修改
git merge branch-name 合并branch-name代码到当前分支
git log 查看各次提交信息

网友评论