Git带你回到过去和未来【6】#匿名分支

33.匿名分支

创建一个项目 MyProject3,完成git 初始化操作。

准备工作:

创建1.txt,add 到暂存区,commit 到仓库;

创建2.txt,add 到暂存区,commit 到仓库;

创建3.txt,add 到暂存区,commit 到仓库;

 

查看状态图:

$git log --decorate --oneline --graph --all

* 0cd17ee (HEAD -> master) 3.txt

* 5cd3921 2.txt

* ccfb829 1.txt

 

切换分支命令

键入命令:git checkout HEAD~

$git checkout HEAD~

Note:checking out 'HEAD~'.

键入该命令后,当前HEAD指针指向上一个快照

 

此时 MyProject3 中3.txt消失

 

查看状态:

$git log --decorate --oneline --graph --all

* 0cd17ee (master) 3.txt

* 5cd3921 (HEAD) 2.txt      # 2.txt为匿名分支

* ccfb829 1.txt

 

创建4.txt,add 到暂存区,commit 到仓库;

查看状态:

$git log --decorate --oneline --graph --all

* 2e7ea4d (HEAD) 4.txt    #4.txt为匿名分支

| * 0cd17ee (master) 3.txt

|/

* 5cd3921 2.txt

* ccfb829 1.txt

 

切换到master分支

$git checkout master

Warning:you are leaving 1 commit behind, not connected to

anyof your branches:

  2e7ea4d 4.txt

Ifyou want to keep it by creating a new branch, this may be a good time

todo so with:

gitbranch <new-branch-name> 2e7ea4d

Switchedto branch 'master'

 

注意:此时切换到master,匿名分支4.txt,若不做创建分支4.txt,之后将不能找到4.txt分支。

 

查看状态:

$git log --decorate --oneline --graph --all

* 0cd17ee (HEAD -> master) 3.txt

* 5cd3921 2.txt

* ccfb829 1.txt

此时匿名分支4.txt消失

 

Checkout 与 reset 区别:

Checkout命令只是切换HEAD指针,而reset命令则是切换整个分支

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值