• 分支创建&查看&切换


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

    git init 
    echo "123" > hello.txt
    git add  hello.txt
    git commit -m "first commit" hello.txt
    
    • 1
    • 2
    • 3
    • 4
    $ 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    2、查看分支

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

    当前没有创建分支,所以默认的分支是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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    3、创建分支

    语法: git branch 分支名

    3.1、创建并查看分支

    git branch hot-fix	# 创建分支 hot-fix
    git branch -a		# 查看分支
    
    • 1
    • 2
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3.2、切换分支

    语法:git checkout 分支名

    git checkout hot-fix
    git branch -a
    
    • 1
    • 2
    $ 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    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(+)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    查看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
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    向量嵌入:AutoGPT的幻觉解法?
    判定转状态+序列问题上树形dp:0909T2
    GaussDB for openGauss部署形态
    pagmo并行全局多目标优化算法库的安装编译与使用
    猿创征文|提升日常工作效率的软件工具分享
    iOS 性能优化方案-弱网优化
    LeetCode每日一题(1325. Delete Leaves With a Given Value)
    LogiKM 2.6.0 配置安装
    Maxwell 是什么?
    Instagram玩法全攻略:跨境电商引流不可或缺的Instagram运营技巧!
  • 原文地址:https://blog.csdn.net/qq_50247813/article/details/132662791