Summary There are simple git commands comprehensively, and you can check them when you use git

All basic git commands, more comprehensive git commands.

git init										//初始化仓库
git status 										//工作区文件状态
git add <file>  								//把文件修改添加到暂存区
git diff <file> 								//比较工作区和暂存区中这个文件的不同
git diff HEAD -- <file>							//比较提交最新版和工作区中该文件的不同
git commit -m  “修改总结”						//把暂存区的所有内容提交到当前分支
git reset --hard HEAD~4 						//版本退回当前版本往前数4个
git reset --hard 3e548c6 						//版本退回到指定版本号
git log   										//查看修改日志,只显示当前版本之前版本
git log --pretty=oneline						//简版的修改日志
git reflog  									//查看版本退回记录,可用来寻找当前版本之后的版本号
git checkout -- <file> 							//丢弃工作区中对改文件的所有修改,还原到暂存区的版本
git reset HEAD <file> 							//把暂存区中的该文件退回工作区,退回的是commit后的第一个add版本
git rm <file>									//删除暂存区中的文件

ssh-keygen -t rsa -C "<邮箱地址>"				//生成ssh密钥,id_rsa是私钥,id_rsa.pub是公钥,将公钥添加到github中
git remote add <ropeName> <远程库的ssh地址>		//关联远程库,初始化库名
git remote rm <ropeName>						//移除已有的关联
git remote -v 									//查看远程库的信息
git push <ropeName> <branch-name> 				//把指定的本地分支提交到远端GitHub上关联的库中,第一次关联在push后面加一个-u
git clone <远程库的ssh地址>						//克隆到本地
git checkout -b dev <ropeName>/dev				//默认克隆的是master分支,该语句创建dev分支从远程的dev中(<ropeName>/dev)
git pull 										//如果push有冲突需要pull下来解决冲突
git pull <ropeName> <远程分支名>:<本地分支名>		//如果push有冲突需要pull下来解决冲突
git branch --set-upstream-to=<ropeName>/<远程分支名> <本地分支名>	//建立远程分支dev和本地分支dev的链接
git branch <branch-name>						//创建分支
git branch 										//查看分支
git checkout <branch-name>						//切换分支
git switch <branch-name>						//切换分支,和上面的命令作用相同,新版使用
git checkout -b <branch-name>					//创建并切换分支
git switch -c <branch-name>						//创建并切换分支,和上面命令的作用相同,新版使用
git merge <branch-name> 						//合并某分支到当前分支,有冲突时需手动解除
git branch -d <branch-name> 					//删除分支
git branch -D <branch-name>						//强行删除分支
git log --graph --pretty=oneline --abbrev-commit		//查看简版分支合并图
git merge --no-ff -m "修改总结" <branch-name>			//合并某分支到当前分支。合并分支时,自动提交后合并
git stash										//保存"现场"。在进行临时的工作之前,先将暂存区中的数据起来。在其他分支可以返回暂存区信息
git stash list									//查看存储信息
git stash apply [stash@{0}]						//恢复"现场",但是不删除存储信息。方括号中是可选参数,用来恢复指定的现场信息(在多次保存现场后有用)。
git stash drop									//删除存储信息。
git stash pop									//恢复"现场",同时删除存储信息。
git cherry-pick <版本号>							//只将某一次提交的修改合并入到当前分支
git rebase										//从远程pull后,简化合并记录为一条线。
git tag <tagname> 								//给当前版本(即要commit的分支)打标签(tagname)
git tag <tagname> <id>							//给对应提交的版本号(id)打标签(tagname)
git tag -a <tagname> -m <content>				//创建加描述的标签
git tag 										//查看所有标签
git show <tagname>								//查看该标签信息
git tag -d <tagname> 							//删除标签
git push <ropeName> :refs/tags/<tagname>		//删除远程标签,先将本地对应标签删除,然后使用该命令
git push <ropeName> <tagname> 					//push标签到远程,
git push <ropeName> --tags						//push所有标签

Learn command Liao Xuefeng's git tutorial

Guess you like

Origin blog.csdn.net/weixin_44223946/article/details/113551643