Когда вы запустите git rebase -i HEAD~4
, git откроет текстовый редактор с файлом, который выглядит примерно так:
pick fc7d27a Change 1
pick 09dd4e6 Change 2
pick 683af92 Change 3
pick a72e15a Change 4
# Rebase 3d8944f..a72e15a onto 3d8944f (4 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
#
# Note that empty commits are commented out
Это «открыть файл в текстовом редакторе» - это интерфейс, который позволяетвам нужно сказать git, что вы хотите сделать, затем выполнить перебазирование.
Измените pick
на squash
(или просто s
) для коммитов, которые вы хотите вставить в предыдущий коммит.Например: затем сохраните и выйдите из редактора.
pick fc7d27a Change 1
squash 09dd4e6 Change 2
squash 683af92 Change 3
squash a72e15a Change 4
Изменения 2, 3 и 4 будут объединены в изменение 1.