Git 我应该如何正确地挤压之前压在主人身上的球?

Git 我应该如何正确地挤压之前压在主人身上的球?,git,Git,我在master分支上,事后来看,我推送了太多的提交消息(或者至少我的队友告诉我是这样)。下面是日志的外观: % git log --oneline fc71bc8 (HEAD -> mainline, origin/master, origin/HEAD) Renamed 'week' to 'period' 3858ca5 Reverted days in year back to 365 a5d19bb Reverted days in year back to 365 635a4f

我在
master
分支上,事后来看,我推送了太多的提交消息(或者至少我的队友告诉我是这样)。下面是日志的外观:

% git log --oneline
fc71bc8 (HEAD -> mainline, origin/master, origin/HEAD) Renamed 'week' to 'period'
3858ca5 Reverted days in year back to 365
a5d19bb Reverted days in year back to 365
635a4fe Submitting revision 2
edb25c7 Removed var_int as it is no longer needed
af1c576 Added unit tests and addressed comments
72b95a1 Built infrastructure for modeling
d31b45a added augmented model
我想挤压提交
3858ca5
a5d19bb
635a4fe
edb25c7
,以及
af1c576
。这将只剩下提交
fc71bc8
72b95a1
d31b45a
。当然,我想保留压缩提交中的代码更改,我只想将它们包装到提交
72b95a1
中。我怎样才能做到最好


我想重申,这些提交已经推送到远程存储库上的
master
。我并不仅仅是在我的本地计算机上像以前那样进行提交。

这通常是通过rebase完成的-I:

git rebase -i d31b45a
# first revision will be 72b95a1, with pick, leave it like that
# the following IDs for the revisions you want to squash, set them to squash
# leave the one for fc71bc8 in pick
# save and exit
# rebase will start running and will open on the editor so you set the message
# for all those squashed commits
# set the message, save  and exit and rebase should finish
# and the squashed revisions should be there

更合适的复制:这适用于尚未推送的代码。如果我需要为已经推送到主程序的代码执行此操作,该怎么办?这会覆盖以前的推送吗?我修改了我的问题,以强调代码已经被推送的事实。