git复习笔记
git基础
- 添加用户名和邮箱
1
2git config --global user.name <yourName>
git config --global user.email <yourEmail> - 查看用户名和邮箱
1
2git config --global user.name
git config --global user.email版本库
- 添加git仓库
1
git init
时光机
- git分为三个区域
工作区/暂存区/仓库
- 把某个文件添加到暂存区(每一次增删改都要重新添加)
1
git add <file>
- 把缓存区中的内容提交到仓库
1
git commit -m <message>
- 查看git管理的仓库中文件的状态
1
git status
- 这里分为几种情况
显示工作区文件的 增加 情况
显示暂存区和仓库中已添加文件的 被修改/删除 情况
不显示未添加文件的 修改/删除 情况
- 查看工作区文件和暂存区/仓库的不同 未添加的文件修改不显示
1
git diff
工作区和暂存区无差别,不显示
工作区和暂存区有区别,显示工作区和仓库的区别
- 撤销修改
清空工作区修改回到上一次add/commit1
git checkout <file>
- 撤销上一次add
1
git reset HEAD <file>
- 删除git管理文件夹下任意文件
1
git rm <file>
- 查看提交记录
1
git log
- 退出查看状态(英文状态下)
1
Q
- 查看日志(每一条归拢到一行)
1
git log --pretty=oneline
- 回退到上一个版本
1
git reset --hard HEAD^
- 回退到上上个版本(以此类推)
1
git reset --hard HEAD^^
- 回退到某一个版本(可以使之前的一个版本,也可以是未来的某一个版本)
1
git reset --hard <版本号,即是之前用查看日志每一行出来的每一个版本至少前四位>
- 查看每一次版本变化
1
git reflog
远程仓库
- 创建.ssh
1
2ssh-keygen -t rsa -C <youremail>
ssh-keygen -t rsa -C "1791738789@qq.com"git remote
- 查看远程仓库关联
1
git remote
- 查看远程仓库关联详细信息
1
git remote -v
- 添加远程仓库关联
1
2git remote add <name> <url>
git remote add origin git@gitee.com:zxwHome/test.git - 删除远程仓库关联
1
git remote remove <name>
- 修改远程仓库关联
1
2git remote set-url <name> <newurl>
git remote set-url origin git@gitee.com:zxwHome/resources.git
- 推送远程仓库
1
2
3
4
5git push [-u] <remoteName> <remoteBranch>
for example:
git push -u origin master
git push origin master
git push - 仓库克隆
1
git clone <url>
分支
- 查看分支
1
git branch
- 创建分支
1
git branch <branchName>
- 删除分支
1
git branch -d <branchName>
- 切换分支
1
git checkout <branchName>
- 创建并且切换分支
1
git checkout -b <branchName>
//TODO
- 合并到当前分支(快速合并)
1
git merge <branchName>
- 合并到当前分支(普通合并)
1
git merge --no-ff -m <message> <branchName>
- 查看分支合并图
1
git log --graph