通过合并压缩/修复提交

Jes*_*ria 2 git github

我已经从分支 A 创建了分支 AB,一段时间后我合并了从 A 到 AB 的新更改,还对 AB 做了一些“正在进行的工作”提交;

现在我只想在第一次提交时留下一条提交消息,但要保存来自合并等的所有数据;

我已经做好了git log --pretty=oneline

a last commit
b merge branch from A
c merge pull request from A
d meger branch from A
e WIP commit
f WIP commit
g WIP commit
h first commit
Run Code Online (Sandbox Code Playgroud)

我正在尝试进行不同的组合git rebase -i {commit},但每次我都会失去一些提交

如何以正确的方式去做?

Dav*_*sch 5

最简单的方法是使用git reset. 此命令允许您将最新提交的所有内容保留在工作目录中,同时将当前分支移动到另一个提交。所以请执行以下操作:

git branch backup        #keeps your current history from getting lost in case you screw up
git reset --soft h       #moves current branch to the first commit (i.e. h)
git commit --amend       #makes commit h contain all the changes you made
Run Code Online (Sandbox Code Playgroud)

一旦验证一切都符合您的要求,您就可以删除分支backup