分支创建&查看&切换

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

powershell 复制代码
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 commit
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt

2、查看分支

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

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

复制代码
$ git branch -v
* master 8624ac6 first commit

Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch
* master

Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch -a
* master

3、创建分支

语法: git branch 分支名

3.1、创建并查看分支

powershell 复制代码
git branch hot-fix	# 创建分支 hot-fix
git branch -a		# 查看分支
复制代码
Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch hot-fix

Administrator@DESKTOP-IL6MV0I MINGW64 /d/Git/git-demo (master)
$ git branch -a
  hot-fix
* master

3.2、切换分支

语法:git checkout 分支名

powershell 复制代码
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-fix
  master

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 commit
 1 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
相关推荐
三84440 分钟前
使用Samba/NFS实现文件共享/自动挂载共享目录/autofs自动挂载服务
linux·服务器·网络
高铭杰1 小时前
万物皆可KV(2)SurrealDB 存储布局分析
linux·服务器
无小道2 小时前
深入解析操作系统文件缓冲区:页缓存、基数树与f_pos的协同设计
linux·缓存·文件缓冲区
AOwhisky3 小时前
Linux(CentOS)系统管理入门笔记(第十二期)——系统管理工具与软件包管理(上篇):Cockpit 与 RPM 包管理
linux·运维·笔记·centos·云计算
寒水馨3 小时前
Linux下载、安装godot-4.7.1-stable(附安装包Godot_v4.7.1-stable_linux.x86_64.zip)
linux·游戏引擎·godot·游戏开发·2d游戏·3d游戏·godot engine
念恒123063 小时前
Socket编程UDP(中)
linux·网络协议·udp
深耕运维十八载云架构实务3 小时前
系统故障玄学之内存明明显示空闲,服务器却频繁卡顿卡死?拆解被忽略的 Linux 隐性内存陷阱
linux
qetfw4 小时前
CentOS 7 搭建 Sendmail + Dovecot 邮件服务器:SMTP、POP3、IMAP 与 TLS
linux·centos
明日清晨4 小时前
printf(“%p\n“,&((struct A *)NULL)->m_float)的原理
linux·服务器·前端
Android系统攻城狮6 小时前
Linux PipeWire深度解析之pw_context_add_spa_lib调用流程与实战(二十九)
linux·运维·服务器·音频进阶·pipewire音频进阶