GIT常用命令

配置用户

$ git config --global user.name "yourname"
$ git config --global user.email "youremail"

生成SSH密钥对

$ sh-keygen -t rsa -C  "youremail@xx"   #生成公钥和私钥

GIT管理的本地结构

在这里插入图片描述

Git管理文件的三种状态

  1. 已修改modified
  2. 已暂存staged
  3. 已提交committed

git常用命令

创建版本库

$ git clone <url>         	#克隆远程版本库
$ git init                	#初始化本地版本库

修改和提交

$ git status				#查看状态
$ git diff					#查看变更内容
$ git add <.|file>			#跟踪所有<.>变动或指定<file>文件
$ git mv <old> <new>		#文件改名
$ git rm [-f] <file>		#删除暂存区和本地文件
$ git rm --cached <file>    #删除暂存区文件
$ git rm commit [-m|-am] "commit message"  			# 提交所有已暂存的文件
$ git rm commit --amend [-m|-am] "commit message"	# 修改最近一次的提交
$ git commit -am "commit message"相当于 git add -u(添加修改的)+ git commit -m

查看提交历史

$ git log [-n]				#查看(n个)提交历史
$ git log -p <file>			#查看指定文件的提交历史
$ git blame <file>			#以列表方式查看指定文件的提交历史

撤销

$ git reset [--mixed(默认)|--soft|--hard] [HEAD~|commitId]  #还原操作,mixed影响暂存区、本地版本仓库,soft影响本地版本仓库,hard影响工作区域、暂存区、版本仓库,HEAD为当前指向的提交版本,一个~代表回退1个提交版本。会删除commitId版本之后的版本,远程提交git push -f。
$ git checkout HEAD <file>     #撤销(暂存区)指定的未提交文件的修改内容
$ git revert <commitId>        #撤销指定的提交,并生成一个新的版本

分支和标签

$ git branch [-a|-v|-vv|-r]   	#显示分支,-a显示本地和远程分支,-v显示本地分支,-vv显示本地分支与远程分支关联情况,-r显示远程分支
$ git branch <new-branch>     	#创建本地新分支
$ git branch -d <branch>        #删除本地分支
$ git checkout <branch/tag>    	#切换到指定分支或标签    
$ git tag                       #列出所有本地标签
$ git tag <tagName>             #基于最新提交创建标签 
$ git tag -d <tagName>          #删除标签
$ git checkout -b <new-branch>  #创建分支并切换新分支

在这里插入图片描述

合并和衍合

$ git merge <branch>        #合并指定分支到当前分支
$ git rebase <branch>       #衍合指定分支到当前分支

远程操作

$ git remote [-v]      				#查看远程版本库信息 
$ git remote show <remote>          #查看指定远程版本库信息
$ git remote add <remote> <url>     #添加远程版本库
$ git remote add <remote> <url>     #添加远程版本库
$ git remote rename <old-name> <new-name>        #修改远程版本库的名称
$ git remote remove <remote>                     #删除远程版本库
$ git remote set-url <remote> <new-url> [<ord-url>]   #修改远程版本库的地址
$ git pull <remote> <r-branch>      #下载代码并快速合并
$ git push <remote> <r-branch>      #上次代码并快速合并 
$ git push --tag                    #上传所有标签
$ git push <remote> <branch>:<r-branch> #向远程版本库中分支r-branch提交本地branch分支,不存在则创建远程分支(不会绑定)
$ git push <remote> :<r-branch>  #向远程版本库中分支r-branch提交空内容,可删除远程分支
$ git push <remote> --delete <r-branch>       #删除远程分支r-beanch
$ git push --set-upstream <remote> <branch>   #设置branch分支与远程分支绑定(同名),不存在则创建远程分支
$ git branch --set-upstream-to=<remote>/<r-branch> <branch>  #设置branch分支与远程分支r-branch绑定
$ git branch --unset-upstream     #解除当前分支与远程分支的绑定

—>官方详细文档



、﹗∕
— 〇 -
╱︱ ヽ
但行好事、莫问前程!
>.freerme[https://blog.csdn.net/freerme]
_________________ *_*______
____ ____ ____
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值