1、常用命令
初始化
git init
添加一个文件到 暂存区。git add . 添加当前目里下所有文件到暂存区
git add README.md
把暂存区域的文件提交到本地 Git 仓库
git commit -m "first commit"
添加远程仓库地址,远程仓库名称为origin,如果需要传到两个远程仓库,可以添加两个
git remote add origin https://github.com/hshy/test.git
git remote add gitee https://gitee.com/hshy/test.git
将本地master 推向远程仓库,加上-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令
git push -u origin master
本地已经关联了github ,从远程出获取更新
git pull origin master
克隆远程仓库
git clone https://github.com/hshy/test.git
git clone -b dev https://github.com/hshy/test.git # 指定分支
2、版本回退
git reset 命令用于把 Git 仓库的文件还原到暂存区域
git reset --hard^ // 一个^号表示回退上一个版本
git reset --hard^^ // 一个^号表示回退上一个版本,两个表示回退至前两个版本
git reset --hard~100 // 回退至前100个版本
git reset --hard 版本号
git reset head~ // 取消上一次的提交
3、分支管理
查看分支
git branch #查看本地分支
git branch -r #查看远程分支
git branch -a #查看所有分支
git branch [branch name] # 本地创建新的分支
git checkout [branch name] #切换分支
git checkout -b [branch name] #创建+切换分支
git push origin [branch name] # 将新分支推送到github
git branch -d [branch name] # 删除本地分支
git push origin :[branch name] #删除github远程分支
4、idea 分支管理
新建分支

image.png

image.png
新建完会自动切换到分支,修改分支内容。提交上传。然后再切换到主干,对分支代码进行合并。

image.png

image.png
网友评论