Git
一、git安装
1.下载
这个就需要去 Git 官网下载对应系统的软件了,下载地址为:
https://git-scm.com/download/
2.安装
一路next完全🆗
二、常用的shell命令
- pwd 获取当前路径
- ls 显示列表下文件
ls-la显示隐藏文件 - cd 打开文件
- mkdir 创建文件夹
- touch 创建文件
- rm 删除
- clear 清除屏幕
三、配置用户名和邮箱
命令如下:
- git config --global user.name “liu”
- git config --global user.email 1284579767@qq.com
- git config --list
- git config user.name
- git help
四、管理git项目
命令如下:
- git init
- git init [name]
- git add [filename](追踪文件)
- git add
五、commit作用是什么
作用:生成项目版本(未被追踪不可以生成)
命令如下:
- git commit
- git commit -m
- git commit -am
六、log追踪
作用:查找操作记录
命令如下:
- git log
- git log -p -2
- git log --author
- git log --online
- git log --graph
- git log --pretty=online
- git log --pretty=format(定制格式)
七、追踪文件修改前后的区别
#命令如下:
- git diff
- git diff --stage
八、文件忽略
命令如下:
- .gitignore
- /node_modules 忽略node_modules文件夹下的所有文件
- *.log 忽略.log结尾的文件
- *.zip 忽略.zip结尾的文件
- git rm -r --cached
九、一键还原
命令如下:
- git checkout --[filename] 恢复到上一次的状态
十、撤销追踪操作与文件还原
命令如下:
- git rest HEAD [filename] 撤销追踪
- git checkout --[filename]
十一、版本回退
命令如下:
- git reset --hard HEAD^ 回退到上一个版本
- git reset --hard HEAD^^ 回退到上上一个版本
- git reset --hard HEAD [hash号] 回退到指定版本
- git reflog 指针理解
十二、回到旧版本(回到旧版本并产生新版本)
- git log
- git checkout [hash]–[filename]
十三、建立切换删除分支
命令如下:
- git branch [name] 建立分支
- git cheackout [branch name] 切换分支
- git cheackout -b [branch name] 建立和切换同时进行
- git branch [name] -d 删除分支
- git branch [name] -D 强制删除分支
十四、理解分支到底是什么
- 什么是分支
可以理解为一个移动盘 - 分支的作用是什么
希望能在另外一个盘里面操作,不影响这个盘里面的内容
十五、如何正确的合并分支
把新的合并到旧的里面,覆盖掉
- git merge[branch name]
十六、如何解决合并时发生的冲突
- git merge[branch name]
- git status 查看冲突原因
- git merge --abort 忽略合并
- 手动选择正确内容
- git commit
十七、如何通过命令查看版本线图
命令如下:
- git log
- git log online
- git log online --graph
- git log online --graph --all
- git log online --graph -[number]
十八、快转机制的意义(拥有分支合并时)
- 实际就是当前maste的将来时
- git merge branchname --no-ff
十九、更多合并的方法
命令如下:
- git merge --no-ff --no-commit[branchname]
- git merge --no-ff --sqash[branchname]
- git merge sqash[branchname]
- git reset --hard ORIG_HEAD
二十、一次性删掉所有不想要的分支
命令如下:
- git branch – merged | egrep -v"(^*lmasterldevelop)" xargs git branch -d