(i) 作者ごとに 1 つのコミット
論理的には不可能だと思います: 次のような一連のコミットがあるとします:
- コミット: A、作者: アルファ
- コミット: B、作者: ベータ
- コミット: C、作者: Alpha
コミット C が B で行われた何かに依存している場合、A と C を並べ替えたり、押しつぶしたりすることはできなくなります。
(ii) 最後のコード行のみを含む元のコミット
そのためには、「git filter-branch --tree-filter」を使用できます。次のスクリプトは子猫を食べる可能性があることに注意してください。単純なテスト リポジトリでしかテストしていないためです。あなたは警告されました:
git filter-branch --prune-empty --tree-filter '
# directory which contains the final version of the project
FINAL_VERSION="$DIRECTORY_WITH_REPOSITORY_OF_FINAL_VERSION"
# directory which contains the filtered version of the repository
FILTER_DIR="$(pwd)"
# apply the current commit in to the final version in reverse mode,
# ignore the rejects
cd "$FINAL_VERSION"
git show "$GIT_COMMIT" > /tmp/original.patch
cat /tmp/original.patch | patch -p1 -t
git diff > /tmp/filtered.patch
# reset the FINAL_VERSION to the original state.
git reset --hard
git clean -f -d -x
# apply the patch which contains the lines which could be reversed on
# the filtered version
cd "$FILTER_DIR"
# revert the last commit
patch -p1 -t < /tmp/original.patch
# apply the filtered patch
patch -p1 -t < /tmp/filtered.patch
# remove the rejects by the modified patch
find -name "*.orig" -o -name "*.rej" | xargs rm -rf
' previousRelease..HEAD
(これは、分岐点に「previousRelease」というタグを付けていることを前提としています。FINAL_VERSION 変数も調整する必要があります。)