Git

119 阅读1分钟

原理图

image.png

基本操作

分支管理

git branch <branchName> //创建一个分支
git branch -d <branchName> //删除一个分支
git branch -v //显示所有分支信息

提交代码

查看状态

添加文件到暂存区

//添加文件内容到暂存区(同时文件被跟踪)
git add

//添加所有文件
git add .

提交代码

git -commit -m 'first commit' //从暂存区提交 -m:注释

撤销

git checkout -- <file> //将文件内容从暂存区复制到工作目录

//撤销暂存区内容
git reset HEAD <file> //将文件内容从上次提交复制到缓存区
git checkout HEAD -- <file> //将内容从上次提交复制到工作目录

日志

git log //查看提交历史记录

git log --online
git log --color --graph

git 命令

git branch

git branch <branchName> //创建一个分支
git branch -d <branchName> //删除一个分支
git branch -v //显示所有分支信息

git checkout

git checkout <branchName> //通过移动HEAD检出版本,可用于切换分支
git checkout -b <branchName> //创件一个分支并切换
git checkout <reference> //将其移动到一个引用
git checkout - //恢复到上一个分支

git reset

//git reset   将当前分支回退到历史某个版本
git reset --mixed <commit> //(默认)
git reset --soft<commit> 
git reset --hard <commit> 

git reflog

image.png

git stash

git stash save "push to stash area" // 通过save 后面传入信息标识 放到stash区
git stash llist //查看收藏的记录
git stash apply stash@{0} //将保存的内容重新恢复到工作目录
git stash drop stash@{0} //将对应的stash记录删除

git stash pop //= git stash apply + git stash drop

参考教程