ちょっと変ですが、gitではかなり一般的な操作を実行できません。基本的に私が欲しいのは、機能ブランチをチェックアウトすることです。ヘッドを使用するのではなく、SHAIDを使用します。このSHAは、マスターブランチからのマージを指します。
問題は、機能ブランチからのコミットなしで、マスターブランチだけを取得することです。現在、マスターブランチで以前に導入されたリグレッションを修正しようとしています。
よりわかりやすくするために、問題のあるリポジトリを再作成するための小さな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
ありがとう。