当前位置: 首页 > news >正文

分支创建查看切换

1、初始化git目录,创建文件并将其推送到本地库

git init 
echo "123" > hello.txt
git add  hello.txt
git commit -m "first commit" hello.txt
$ git init
Initialized empty Git repository in D:/Git/git-demo/.git/
Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ echo "123" > hello.txt
Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git add  hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git commit -m "first commit" hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
[master (root-commit) 8624ac6] first commit1 file changed, 1 insertion(+)create mode 100644 hello.txt

2、查看分支

 git branch -v		# 显示当前分支和版本号git branch 		# 只显示当前分支git branch -a		# 显示所有的分支

当前没有创建分支,所以默认的分支是master

$ git branch -v
* master 8624ac6 first commitAdministrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch
* masterAdministrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch -a
* master

3、创建分支

语法: git branch 分支名

3.1、创建并查看分支

git branch hot-fix	# 创建分支 hot-fix
git branch -a		# 查看分支
Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch hot-fixAdministrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch -ahot-fix
* master

3.2、切换分支

语法:git checkout 分支名

git checkout hot-fix
git branch -a
$ git checkout hot-fix
Switched to branch 'hot-fix'Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (hot-fix)
$ git branch -a
* hot-fix		# 目前分支是指向的 hot-fixmaster

3.3、修改工作区的文件上传到本地库
$ echo “456” >> hello.txt

Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (hot-fix)
$ cat hello.txt
123
456	# 新增记录Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (hot-fix)
$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
$ git commit -m "hot-fix commit" hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
[hot-fix 35926cb] hot-fix commit1 file changed, 1 insertion(+)

查看windows目录的文件

在这里插入图片描述
#可以看出分支已经多了一个hot-fix

查看hot-fix对应的版本

Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (hot-fix)
$ git reflog
35926cb (HEAD -> hot-fix) HEAD@{0}: commit: hot-fix commit
8624ac6 (master) HEAD@{1}: checkout: moving from master to hot-fix
8624ac6 (master) HEAD@{2}: commit (initial): first commit
http://www.lryc.cn/news/156114.html

相关文章:

  • 参编三大金融国标,奇富科技以技术促行业规范化演进
  • 芯片开发之难如何破解?龙智诚邀您前往DR IP-SoC China 2023 Day
  • Gof23设计模式之策略模式
  • SAP 物料主数据屏幕增强
  • 数据库-索引
  • Excel·VBA二维数组组合函数的应用实例
  • hive anti join 的几种写法
  • 使用Android原生制作毛玻璃效果图片
  • 软件设计的七大原则
  • Windows下安装配置Nginx
  • 数据结构类型
  • WPF元素绑定
  • centos编译升级cmake,痛苦的Linux小白
  • Unity资源无法下载 反复提示需同意Terms of Service和EULA 同意后无效的解决方案
  • 记录--vue 拉伸指令
  • 前端缓存方法有哪些?cookie有哪些属性?
  • 在PHP8中遍历数组-PHP8知识详解
  • 代码随想录算法训练营之JAVA|第四十三天|139. 单词拆分
  • 解决VUE3项目部署后存在缓存页面不更新的问题
  • 私募证券基金动态-23年8月报
  • Qt/C++音视频开发49-推流到各种流媒体服务程序
  • 深度学习学习笔记——解决过拟合问题的方法:权重衰减和暂退法,与正则化之间的关系
  • 【Leetcode Sheet】Weekly Practice 5
  • STM32 SPI对存储芯片发送写是能命令后一直忙等待
  • MySql学习笔记01——SQL的相关术语
  • SpringMVC入门指南
  • mysql忘记root密码如何解决?
  • ChatGPT可以生成Windows密钥
  • jupyter notebook内核启动报错:ImportError: DLL load failed while importing _device
  • 蓝桥杯备赛(Day5)——二叉树