Git闯关游戏:Learn Git Branching Level 2-1 分离HEAD

295 阅读1分钟



Level 2-1 《分离HEAD》

2022-08-01_114847.png

游戏答案:

git checkout c4



准备实验环境

# 准备一个空目录
mkdir level-2-1
cd level-2-1

# 初始化本地仓库
git init

# 在master分支提交两次
echo 111>>a.txt
git add .
git commit -m "c0"
echo 222>>a.txt
git add .
git commit -m "c1"

# 创建bugFix分支,但不切换到bugFix
git branch bugFix

# 在master分支继续提交一次
echo 333>>a.txt
git add .
git commit -m "c2"

# 切换到bugFix分支然后提交两次
git checkout bugFix
echo 444>>a.txt
git add .
git commit -m "c3"
echo 555>>a.txt
git add .
git commit -m "c4"

# 查看提交树
git log --graph --pretty=oneline --all



真实答案:

首先需要查看你的提交日志中的这个id:

image.png

# 使用上面id的前四位即可:
git checkout c2fe

执行checkout时会看到提示:

image.png

查看提交树会看到HEAD处于分离状态:

git log --graph --pretty=oneline --all

image.png

查看仓库状态:

git status

image.png