Git复习01——常用命令+分支操作

本系列笔记来自b站尚硅谷~ 真不错~

Git

Git是一个免费的、开源的分布式版本控制工具 VS 集中式版本工具

版本控制

在这里插入图片描述

为什么需要版本控制?

个人开发过渡到团队协作

版本控制工具

  1. 集中式版本工具

SVN …

在这里插入图片描述

事分两面,有好有坏。这么做显而易见的缺点是中央服务器的单点故障。如果服务器

宕机一小时,那么在这一小时内,谁都无法提交更新,也就无法协同工作。

  1. 分布式版本控制工具

Git…
在这里插入图片描述

工作机制

在这里插入图片描述

代码托管中心

在这里插入图片描述

Git安装

安装 无空格非中文

都下一步 除了下面这一步

在这里插入图片描述

git --version

常用命令

在这里插入图片描述

git config --global user.name = zhangsan
git config --global user.email = zhangsan@qq.com  # 虚拟账号也可以 不需要真实的邮箱

linux命令都可以使用 git 和 linux是同一个人开发的

yy p vi中的复制粘贴

git add hello.txt  #提交到暂存区

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt
git rm --cached hello.txt  #从暂存区移走了 文件真实还在
git commit -m "提交的信息" hello.txt  #提交到本地库

git reflog #查看历史记录

在修改hello.txt 再提交 此时本地库有两个版本的hello.txt 当电脑上只显示一个hello.txt

查看历史记录

git log   # 查看详细信息
git reflog # 查看缩短信息 
## 版本穿梭
git reset --hard 版本号 

git reflog  # 看指针
86159@DESKTOP-2O58D28 MINGW64 /e/项目 (master)
$ git reflog
8373e29 (HEAD -> master) HEAD@{0}: commit: second commit
dd983a6 HEAD@{1}: commit (initial): first commit

86159@DESKTOP-2O58D28 MINGW64 /e/项目 (master)
$ git reset --hard dd983a6
HEAD is now at dd983a6 first commit

86159@DESKTOP-2O58D28 MINGW64 /e/项目 (master)
$ git reflog
dd983a6 (HEAD -> master) HEAD@{0}: reset: moving to dd983a6
8373e29 HEAD@{1}: commit: second commit
dd983a6 (HEAD -> master) HEAD@{2}: commit (initial): first commit

86159@DESKTOP-2O58D28 MINGW64 /e/项目 (master)
$ cat hello.txt
hello atguigu!
hello atguigu!
hello atguigu!
hello atguigu!
hello atguigu!
hello atguigu!

Git分支

从右往左看

在这里插入图片描述

开发自己分支的时候不会影响主分支的使用 相当于副本

在这里插入图片描述

分支操作

在这里插入图片描述

# 查看分支
$ git branch -v
* master dd983a6 first commit


# 创建分支
$ git branch hot-fix   # 创建分支

$ git branch -v
  hot-fix dd983a6 first commit
* master  dd983a6 first commit


# 切换分支
git checkout hot-fix
# 修改hello.txt 
git add hello.txt
git commit -m "hot-fix first commit"  hello.txt
cat hello.txt # 新修改的文件   和master分支的hello.txt不一样


# 分支合并
#要在master分支上合并其他分支
git merge hot-fix      #合并 hot-fix 分支

代码冲突

合并分支时,两个分支在同一个文件的同一个位置有两套完全不同的修改。Git无法替我们决定使用哪一个。必须人为决定新代码内容。

vim hello.txt
修改第2行
git add hello.txt
git commit -m "master  test"  hello.txt

git checkout hot-fix
vim hello.txt
修改第3行
git add hello.txt
git commit -m "hot-fix  test"  hello.txt

git checkout master
git merge hot-fix

在这里插入图片描述

手动合并代码

vim hello.txt

修改前

在这里插入图片描述

修改后

<<< ======== >>> 里面选一行 把另一行删掉 特殊符号也要删掉

在这里插入图片描述

:wq
git add hello.txt
# 不能带文件名
git commit -m "merge test"
cat hello.txt


git checkout hot-fix
cat hello.txt  #还是自己的内容
#结论:只会修改合并的分支 , 不会修改被合并的分支

团队协作

团队内协作

在这里插入图片描述

跨团队协作

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值