1、git 一个免费的、开源的分布式版本控制系统,可以快速高效的处理从小型到大型的各种项目。
2、git易于学习,占地面积小,性能快,有廉价的本地库,方便的暂存区和多个工作流分支等特性。
3、git常用命令:
git config --global user.name 用户名 设置用户签名 -> 区分不同操作者,首次安装必须设置
git config --global user.email 邮箱 设置用户邮箱
git init 初始化本地库
git status 查看本地库状态
4、安装git
5、编辑文件内容
新建文件夹git-demo,打开该文件夹,右键打开Open Git Bash here ,输入 git init进行初始化,生成.git文件。
vim hello.txt 新增hello文件
-> i 进入编辑 输入内容“hello git”
-> esc退出编辑(yy复制,p粘贴)
-> 输入:wq 保存内容
-> ll 查看文件信息
-> cat hello.txt 查看文件内容
-> tail -n 1 hello.txt 查看末尾最后一行
-> git status 查看本地库状态,若显示红色,则是没有进行追踪。
6、添加/删除暂存区
git add hello.txt ->git status ->显示new file hello.txt(暂存区)
git rm --cached hello.txt(删除暂存区中的) -> 显示hello.txt是红色,则删除成功。
7、提交本地库
git commit -m "日志信息" 文件名,如: git commit -m "first commit" hello.txt
git reflog 查看引用日志信息
git log 查看详细日志信息
8、修改文件
vim hello.txt
-> 修改内容
-> :wq 保存
-> git status 查看
-> (modified: hello.txt)
-> git add 添加暂存区
-> git commit -m "second commit" hello.txt 提交本地库
-> git reflog 查看日志信息
-> cat hello.txt 查看文件内容
9、ctrl+l 清屏
10、版本穿梭
该部分主要是依靠指针指向。
git reflog查看版本信息,前边为版本号
git reset --hard 版本号(复制版本号,快捷方式:复制双击左键,粘贴鼠标中键),选择想要退回哪一版本。
11、分支:对其他分支无影响,并行开发,提高开发效率。
一个分支就是一个单独的副本,分支底层也是指针的引用。
12、分支的操作
git branch 分支名 创建分支
git branch -v 查看分支
git checkout 分支名 切换分支
git merge 分支名 把指定的分支合并到当前分支上
13、创建分支
git branch hot-fix
-> git branch -v 查看分支
-> git checkout hot-fix 切换分支
-> vim hello.txt
-> git status
-> git add hello.txt 添加暂存区
-> git commit -m "hot-fix first commit" hello.txt 提交本地库
-> cat hello.txt 查看文件内容
14、切换分支
git checkout master
15、合并分支
在master上合并hot-fix,将hot-fix 合到master中
git merge hot-fix -> cat hello.txt
16、产生冲突(当master和hot-fix都修改时且修改内容不同时会产生冲突)-->手动解决
在master修改上 vim hello.txt , hot-fix 也修改内容 ->添加暂存区 ->提交本地库 ->git checkout master 切换到master -> git merge hot-fix 合并分支 ->Automatic merge failed;fix conflicts and then commit the result 冲突 -> vim hello.txt -> <<<< HEAD Hello master! hello git! ======= hello git!Hello hot-fix! >>>>hot-fix 删除不想保存的部分以及多余的符号 ->:wq保存 -> git add hello.txt 添加暂存区 ->git commit -m "conflict commit"提交本地库(这时提交本地库不能加文件名,因为两分支都修改了hello.txt) -> cat hello.txt 合并成功 -> git checkout hot-fix ->cat hello.txt (内容不变,说明合并分支,只合并想合并的,master中合并,但hot-fix中不变)