我已经从分支A创建了分支AB,我已经合并了一段时间后从A到AB的新变化,也做了一些"正在进行的工作"承诺给AB;
现在我想只留下一个提交消息与firs commit但是要保存合并等所有数据;
我已完成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
git rebase -i {commit}
我正尝试对{{1}}进行不同的组合,但每次我失去一些提交
如何正确地做到这一点?
答案 0 :(得分:3)
最简单的方法是使用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
根据需要验证所有内容后,您可以删除分支backup
。