这有点奇怪,但我无法用 git 完成一个非常常见的操作。基本上我想要的是检查一个功能分支,而不是使用它的头部,而是使用 SHA id。此 SHA 指向来自 master 分支的合并。
问题是我得到的只是主分支,没有来自功能分支的提交。目前我正在尝试修复之前在 master 分支中引入的回归。
为了更具描述性,我制作了一个小型 bash 脚本来重新创建问题存储库:
#!/bin/bash
rm -rf ./.git
git init
echo "test1" > test1.txt
git add test1.txt
git commit -m "test1" -a
git checkout -b patches master
echo "test2" > test2.txt
git add test2.txt
git commit -m "test2" -a
git checkout master
echo "test3" > test3.txt
git add test3.txt
git commit -m "test3" -a
echo "test4" > test4.txt
git add test4.txt
git commit -m "test4" -a
echo "test5" > test5.txt
git add test5.txt
git commit -m "test5" -a
git checkout patches
git merge master
#Now how to get a branch having all commits from patches + test3.txt + test4.txt - test5.txt ???
基本上我想要的只是用文件1-4签出分支“补丁”,但不包括test5.txt。
正在做:
git checkout [sha_where_test4.txt_entered]
... 只给出一个带有 test1、test3、test4 的分支,但不包括 test2.txt
更复杂的例子:
#!/bin/bash
rm -rf ./.git
git init
echo "test1" > test1.txt
git add test1.txt
git commit -m "test1" -a
git checkout -b patches master
echo "test2" > test2.txt
git add test2.txt
git commit -m "test2" -a
git checkout master
echo "test3" > test3.txt
git add test3.txt
git commit -m "test3" -a
echo "test4" > test4.txt
git add test4.txt
git commit -m "test4" -a
echo "test5" > test5.txt
git add test5.txt
git commit -m "test5" -a
git checkout patches
git merge master
echo "test6" > test6.txt
git add test6.txt
git commit -m "test6" -a
#Now how to get a branch having all commits from patches + test3.txt + test4.txt - test5.txt ???
git log --topo-order | cat
# Now I need something to help me going back to history
# without manually calculating that patches~2 sha's
git checkout -b patches.tmp master~1
git merge patches~2
谢谢。