Redoing Commit History in GIT Without Rebase

后端 未结 2 1766
独厮守ぢ
独厮守ぢ 2021-02-05 06:33

Since asking my last question which turned out to be about rebasing with GIT, I have decided that I don\'t want to rebase at all. Instead I want to:

  1. Branch
相关标签:
2条回答
  • 2021-02-05 07:06

    The easiest thing to do is a soft reset.

    So checkout your topic branch:

    git checkout -b topic master
    

    work, work, work.

    git commit
    git commit
    git commit
    git commit
    

    Happy with this, you can make a new single commit on top of master

    git reset --soft master
    git commit
    

    Now merge to master (it will be a fast-forward) and tidy up the topic branch. (Note that you don't need to do this if you are prepared to remember or tag where master was and just work on master without branching, you could have just done git reset --soft old-master and git commit and you wouldn't need these last clean-up steps.)

    git checkout master
    git merge topic
    git branch -d topic
    
    0 讨论(0)
  • 2021-02-05 07:23

    You can also use git merge with the --squash option.

    0 讨论(0)
提交回复
热议问题