首页 > 解决方案 > git rebase -i HEAD~2 的问题

问题描述

这是我的 git 日志:

$ git log --oneline
0729a5e (HEAD -> feature/fork_deploy_function) merge with gitlab
0a6421d implement aws kubernetes deploy phase1
bde4da0 (origin/feature/fork_deploy_function) partially implement kubenetes deployment

bde4da0是 gitlab 中的最新版本,我做了一个 local commit0a6421d和一个 pull and merge branch commit 0729a5e。现在,在我将本地提交推送到 gitlab 之前,我想使用 压缩最后两个提交0729a5e0a6421d一个提交,令人惊讶的git rebase -i HEAD~2是,当我运行它时,我得到了提交bde4da0,并且0a6421d在编辑器中而不是0729a5eand 0a6421d。见下文:

pick 0a6421d implement aws kubernetes deploy phase1
pick bde4da0 partially implement kubenetes deployment

怎么会这样?在这种情况下如何压缩前两个提交?谢谢

标签: gitgitlab

解决方案


不知道为什么,但这不应该失败:

git checkout 0729a5e
git reset --soft bde4da0
# all changes introduced by the last two revisions will be in index, ready to be committed
git commit -m "squash"
# if you like the result
git branch -f feature/fork_deploy_function

推荐阅读