分支创建&查看&切换

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
相关推荐
readhere7 小时前
从ZYNQ7000开发板,学会启动嵌入式Linux系统——入门学习:EBAZ4205篇目录
linux·启动·嵌入式linux·zynq7000·ebaz4205
打工仔折腾 AI8 小时前
在 Ubuntu ARM64 部署 Q1 V3.0 MuJoCo 模型:加载、单步推理与执行器响应解析
linux·运维·人工智能·python·深度学习·ubuntu·性能优化
‎ദ്ദിᵔ.˛.ᵔ₎9 小时前
关于Linux 线程局部存储的认识
linux·运维
小小de风呀11 小时前
de风——【从零开始学习Linux】(九):进程基础 —— 从冯诺依曼体系到 fork 创建进程
linux·学习
晚风吹北巷12 小时前
Linux复习篇(自用)
linux·运维·服务器·1024程序员节
by2099913 小时前
Linux 压缩传输、进程查看与权限管理
linux·经验分享·1024程序员节
无足鸟ICT14 小时前
【RHCA+】reboot命令(重启)
linux·运维·服务器·1024程序员节
DYWorker00114 小时前
第1课:基于正点原子RK3568开发板读懂Linux内核
linux·运维·网络
Android系统攻城狮15 小时前
Linux FFmpeg深度解析之avformat_open_input调用流程与实战(一)
linux·运维·ffmpeg·车载音视频·ffmpeg音视频·音视频进阶手册