Git: How to rebase and squash commits from branch to master?

前端 未结 2 1573
慢半拍i
慢半拍i 2021-01-31 18:25

I\'m trying to rebase and squash all my commits from current branch to master. Here is what I\'m trying to do:

git checkout -b new-feature

make

2条回答
  •  臣服心动
    2021-01-31 18:54

    Lets go though the steps.

    1 - We create a new feature branch

    git checkout -b new-feature
    

    2 - Now you can add/remove and update whatever you want on your new branch

    git add 
    git commit -am "Added new file"
    git rm 
    git commit -am "Removed a file"
    cat "add more stuff to file" >> 
    git commit -am "Updated files"
    

    3 - Next, pick and squash any commits down into one nice pretty commit message

    git rebase -i master
    

    The key thing you need to remember here is to change the text that says "pick" to "squash" for all of the commits after the first commit. This will squash all of the commits down to your master branch.

    4 - Select the master branch

    git checkout master
    

    5 - Move the HEAD and the master branch to where new-feature is:

    git rebase new-feature
    

    You can try all of the commands out in this visual tool: http://pcottle.github.io/learnGitBranching/

提交回复
热议问题