两个分支 - master
和feature
- 与git merge --no-ff
合并。后来的feature
分支被删除了。树看起来像那样:
* (master) A new feature added to the master
|\
| * yet another small commit
| * another small commit
| * small commit
|/
* Master before the feature was added
我想从树中清除那些小提交,看起来像:
* (master) A new feature added to the master
* Master before the feature was added
怎么做?当地的回购还没有推出。
答案 0 :(得分:4)
我愿意
git checkout master
git reset --soft <HASH of commit "Master before the feature was added">
git commit -m "A new feature added to the master"
或者你可以使用
git commit -c ORIG_HEAD
重用原始合并提交中的提交消息。
答案 1 :(得分:2)
让我们假设您的仓库看起来像这样(我需要提交SHA)
* 82daefb - (HEAD, master) A new feature added to the master (15 seconds ago)
|\
| * 6e156b0 - yet another small commit (84 seconds ago)
| * ccc4753 - another small commit (2 minutes ago)
| * e76a659 - small commit (2 minutes ago)
|/
* 3041679 - Master before the feature was added (2 minutes ago)
git checkout -b feature && git reset --hard 6e156b0
git co master && git reset --hard 3041679
git merge feature --squash
git commit -m "A new feature added to the master"
最后你的树看起来像
* 6bf734c - (HEAD, master) A new feature added to the master (68 seconds ago)
* 3041679 - Master before the feature was added (5 minutes ago)