如果您的目的是在推送之前对现有提交进行更改,
需要在本地进行完全更改并再次提交更改
这将在您的 git 日志中列出两个提交。
将这两个提交合并为一个提交并推送。
要合并两个提交,请按照以下步骤操作
说你的历史是
$ git log --pretty=oneline
a931ac7c808e2471b22b5bd20f0cad046b1c5d0d c
b76d157d507e819d7511132bdb5a80dd421d854f b
df239176e1a2ffac927d8b496ea00d5488481db5 a
也就是说,a 是第一次提交,然后是 b,最后是 c。
运行git rebase --interactive HEAD~2 给你一个编辑器
pick b76d157 b
pick a931ac7 c
# Rebase df23917..a931ac7 onto df23917
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
将 b 的选择更改为 squash 将导致您看到的错误,但如果您通过将文本更改为将 c 压缩为 b
pick b76d157 b
s a931ac7 c
and save-quitting your editor, you'll get another editor whose contents are
# This is a combination of 2 commits.
# The first commit's message is:
b
# This is the 2nd commit message:
c
When you save and quit, the contents of the edited file become commit message of the new combined commit:
$ git log --pretty=oneline
18fd73d3ce748f2a58d1b566c03dd9dafe0b6b4f b and c
df239176e1a2ffac927d8b496ea00d5488481db5 a