Git 学习进阶篇 - 分支与合并

Git brach 分支

Git可以创建多个分支,用于对不同版本代码分别进行维护操作。

Git对每个分支默认读取最新commit索引

branch操作常用命令:

命令 描述 实例
git branch xx 创建分支 git branch test,创建test分支
git checkout xx 切换分支 git checkout test,切换到分支test
Administrator@Just-pc MINGW32 /g/git_test/git_repo (master)
$ git branch test               //创建test分支
$ ls   //查看master分支下文件,只有master.d
master.d
$ git checkout test             //切换到 test分支
Switched to branch 'test'
Administrator@Just-pc MINGW32 /g/git_test/git_repo (test)
$ vim test.d                    //添加文件 test.d
$ git add .
$ git commit -m 'first commit on branch test'
[test be2635d] first commit on branch test
 1 file changed, 1 insertion(+)
 create mode 100644 test.d
$ git checkout master           //切换为maste分支
Switched to branch 'master'

Administrator@Just-pc MINGW32 /g/git_test/git_repo (master)
$ ls                            //maser分支显示的是之前的最新的commit提交引用
master.d

如何让引用指向某一固定提交呢?如指向某些发布的版本, tag!

Git tag

分类:
- 轻量级,本地的引用;
- 带注解的,就是之前存储在g**it对象中的Git tag对象**。

相关命令:

命令 描述 实例
git tag 创建本地tag git tag “V0” SHI-ID
git tag -a 创建注解tag
git show 查看tag内容 git show V0
git checkout 切换到tag git checkout V0

首先,查看当前的历史记录

$ git config --global alias.lol  "log --oneline --all --decorate --graph"  //定义别名
$ git lol   // 显示所有提交信息

* be2635d (test) first commit on branch test
* 629aa7f (HEAD -> master) second commit on master
* 5154992 master.d first time commit

create tag

Administrator@Just-pc MINGW32 /g/git_test/git_repo (master)
$ git tag "V0" 5154992              //本地
$ git tag -a "MASTER_FIRST" 5154992 //注解

再次查看历史

Administrator@Just-pc MINGW32 /g/git_test/git_repo (master)
$ git lol                           // 在索引 5154992中以包含创建的两个tag
* be2635d (test) first commit on
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值