0

コミット 1->2->3->4->5 があるとしましょう 履歴が長すぎるかもしれないと思ったので、ログで 1、2、3 を 1 つにマージして、たとえば 1'->2-> のようにします3->4->5 どうすればこれを行うことができますか? リベースを使用する必要がありますか? リベース後にリモートリポジトリにプッシュできないようです。前もって感謝します。

4

1 に答える 1

0

最初に対話型リベース モードに入ります

git rebase -i HEAD~5

(5をスカッシュしたいコミットの数に置き換えてください)

次に、git book Squashing commmits -part の指示に従います。

gitブックから:

インタラクティブなリベース ツールを使用して、一連のコミットを 1 つのコミットにまとめることもできます。このスクリプトは、リベース メッセージに役立つ指示を入れます。

#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

「pick」または「edit」の代わりに「squash」を指定すると、Git はその変更とその直前の変更の両方を適用し、コミット メッセージをマージします。したがって、これら 3 つのコミットから 1 つのコミットを作成する場合は、スクリプトを次のようにします。

pick f7f3f6d changed my name a bit
squash 310154e updated README formatting and added blame
squash a5f4a0d added cat-file

エディターを保存して終了すると、Git は 3 つの変更をすべて適用し、エディターに戻って 3 つのコミット メッセージをマージします。

# This is a combination of 3 commits.
# The first commit's message is:
changed my name a bit

# This is the 2nd commit message:

updated README formatting and added blame

# This is the 3rd commit message:

added cat-file

それを保存すると、以前の 3 つのコミットすべての変更を導入する単一のコミットが作成されます。

于 2013-04-03T09:32:55.230 に答える