How do I squash two non-consecutive commits?

前端 未结 5 2179
执笔经年
执笔经年 2020-11-30 17:16

I\'m a bit new to the whole rebasing feature within git. Let\'s say that I made the following commits:

A -> B -> C -> D

Afterward

5条回答
  •  心在旅途
    2020-11-30 18:08

    Interactive rebase works well until you have big feature branch with 20-30 commits and/or couple of merges from master or/and fixing conflicts while you was commiting in your branch. Even with finding my commits through history and replacing pick with squash doesn't worked here. So i was looking for another way and found this article. I did my changes to work this on separate branch:

    git checkout master
    git fetch
    git pull
    git merge branch-name
    git reset origin/master
    git branch -D branch-name
    git checkout -b branch-name
    git add --all
    #Do some commit
    git push -f --set-upstream origin branch-name
    

    Before this I got my pull request with about ~30 commits with 2-3 merges from master + fixing conflicts. And after this I got clear PR with one commit.

    P.S. here is bash script to do this steps in automode.

提交回复
热议问题