分支创建&查看&切换

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
相关推荐
多多*11 分钟前
OJ在线评测系统 登录页面开发 前端后端联调实现全栈开发
linux·服务器·前端·ubuntu·docker·前端框架
王哲晓1 小时前
Linux通过yum安装Docker
java·linux·docker
gopher95111 小时前
linux驱动开发-中断子系统
linux·运维·驱动开发
码哝小鱼2 小时前
firewalld封禁IP或IP段
linux·网络
鼠鼠龙年发大财2 小时前
【x**3专享】安装SSH、XFTP、XShell、ARM Linux
linux·arm开发·ssh
nfgo2 小时前
快速体验Linux发行版:DistroSea详解与操作指南
linux·ubuntu·centos
Rookie_explorers2 小时前
Linux下go环境安装、环境配置并执行第一个go程序
linux·运维·golang
weixin_424215842 小时前
shell运算实战案例-KFC点餐系统
linux·centos
小黑爱编程3 小时前
【LInux】HTTPS是如何实现安全传输的
linux·安全·https
BeyondESH3 小时前
Linux线程同步—竞态条件和互斥锁(C语言)
linux·服务器·c++