Примітка. Ні в якому разі не слід змінювати комітети, які були перенесені на інше репо, якщо ви не знаєте наслідків .
git log --oneline -4
D commit_message_for_D
C commit_message_for_C
B commit_message_for_B
A commit_message_for_A
git rebase --interactive
pick D commit_message_for_D
pick C commit_message_for_C
pick B commit_message_for_B
pick A commit_message_for_A
Введіть i(Введіть VIM у режим вставки)
Змініть список, щоб він виглядав так (Вам не потрібно видаляти або включати повідомлення про фіксацію). Не помиляйтеся squash! :
pick C commit_message_for_C
pick B commit_message_for_B
pick A commit_message_for_A
squash D
Введіть Escпотім ZZ(Збереження та вихід VIM)
# This is a combination of 2 commits.
# The first commit's message is:
commit_message_for_D
# This is the 2nd commit message:
commit_message_for_A
Тип i
Змініть текст так, як ви хочете виглядати нове повідомлення про фіксацію. Я рекомендую, щоб це був опис змін у фіксації Aта D:
new_commit_message_for_A_and_D
Введіть EscпотімZZ
git log --oneline -4
E new_commit_message_for_A_and_D
C commit_message_for_C
B commit_message_for_B
git show E
(You should see a diff showing a combination of changes from A and D)
Тепер ви створили нову комісію E. Здійснюється Aі Dбільше не входить у вашу історію, але їх уже немає. Ви можете їх відновити в цей момент і на деякий час git rebase --hard D( git rebase --hardзнищить будь-які локальні зміни! ).