したがって、リベースするときは、誤ってファイルを追加したコミットと、追加したいコミットの両方をその順序で編集することを選択します。ファイルが後のコミットにあるが、以前のコミットにある必要がある場合は、行を並べ替える必要があります。たとえば、私は
pick 8de731b Commit with missing file.
pick bbef925 Commit with too many files.
pick 52490ce More history.
に変更する必要があります
edit bbef925 Commit with too many files.
edit 8de731b Commit with missing file.
pick 52490ce More history.
それで、
# In the commit containing an extra file
git reset HEAD^ badfile.c
git commit --amend
git rebase --continue
# Now in the commit to add it to
git add badfile.c
git commit --amend
git rebase --continue
残念ながら、1 つのブランチで履歴を編集する場合、すべてのブランチで履歴を編集しないようにする方法はわかりません。このような問題を回避するには、リベースをできるだけ早く行う必要があります。ここでの私の単純なケースでは、マスターと他のブランチをマージできますが、コミットはマージされません。次に、マスターでリベースし、次のようにコミットを並べ替えてスカッシュする必要があります。
pick 7cd915f Commit with missing file.
fixup 8de731b Commit with missing file. #This was the higher of the two entries
pick 8b92c5a Commit with too many files.
fixup bbef925 Commit with too many files. #This was the higher of the two entries
pick 94c3f7f More history.
fixup 52490ce More history. #This was the higher of the two entries
後期編集:元の回答からの持ち越しとして、コミット履歴を誤って並べ替えていることに気付きました。リベースの行を入れ替えると、コミットする順序が変わります。編集後、再度リベースして元のコミット順序に戻すことができます。