私は別の方法を数回使用しました。実際、これはマニュアルgit rebase -i
であり、いくつかのコミットを押しつぶしたり分割したりするなど、いくつかのコミットを再配置する場合に役立ちます。主な利点は、すべてのコミットの運命を一度に決定する必要がないことです。また、リベース中とは異なり、プロセス中はすべての Git 機能を利用できます。たとえば、元の履歴と書き換えられた履歴の両方のログをいつでも表示したり、別のリベースを実行したりすることもできます!
簡単に読めるように、次の方法でコミットを参照します。
C # good commit after a bad one
B # bad commit
A # good commit before a bad one
最初の履歴は次のようになります。
x - A - B - C
| |
| master
|
origin/master
次のように再作成します。
x - A - B*- C'
| |
| master
|
origin/master
手順
git checkout B # get working-tree to the state of commit B
git reset --soft A # tell Git that we are working before commit B
git checkout -b rewrite-history # switch to a new branch for alternative history
git add
(git add -i
など)を使用して古いコミットを改善しますgit stash
。古いコミットを 2 つ以上に分割することもできます。
git commit # recreate commit B (result = B*)
git cherry-pick C # copy C to our new branch (result = C')
中間結果:
x - A - B - C
| \ |
| \ master
| \
| B*- C'
| |
| rewrite-history
|
origin/master
終わりましょう:
git checkout master
git reset --hard rewrite-history # make this branch master
または、コマンドを 1 つだけ使用します。
git branch -f master # make this place the new tip of the master branch
それだけです、あなたはpush
今あなたの進歩を遂げることができます。
最後のタスクは、一時ブランチを削除することです。
git branch -d rewrite-history