- 可以到这里下载安装
Git: git-scm.com/download/wi…- Learn Git Branching游戏在这里:learngitbranching.js.org/?locale=zh_…
Level 5-2 《两个父节点》
这一关对两个分支进行了合并,合并之后的提交有两个父提交,使用^2可以访问它的另一个父提交,不仅在游戏里学习,你还可以在真实环境中进行实验。
游戏答案:
# 上一个提交(~)的另一个父提交(^2)的上一个提交(~)
git branch bugWork HEAD~^2~
准备实验环境
下面命令完整CV到Windows cmd命令行窗口中执行:
# 准备一个空目录
mkdir level-5-2
cd level-5-2
# 初始化本地仓库,然后做两次提交
git init
echo 111>>a.txt
git add .
git commit -m "c0"
echo 222>>a.txt
git add .
git commit -m "c1"
# 创建并切换到another提交,然后做一次提交
git checkout -b another
echo 333>>a.txt
git add .
git commit -m "c2"
# 切换到master,再做两次提交
git checkout master
echo 444>>a.txt
git add .
git commit -m "c3"
echo 555>>a.txt
git add .
git commit -m "c4"
# 再到another分支做一次提交
git checkout another
echo 666>>a.txt
git add .
git commit -m "c5"
# 切换到master,然后把another合并到master
git checkout master
git merge another
合并时如果有文件冲突,需要先手动解决冲突后再提交文件。
# 手动修正a.txt后继续
# 完成合并,生成新的提交c6
git add .
git commit -m "c6"
# 在master再提交一次
echo 777>>a.txt
git add .
git commit -m "c7"
# 删除another分支
git branch -d another
# 查看提交树
git log --graph --pretty=oneline --all
真实答案:
# 上一个提交(~)的另一个父提交(^2)的上一个提交(~)
git branch bugWork "HEAD~^2~"
# 查看提交树
git log --graph --pretty=oneline --all