- git rebase
git rebase 我通常會(huì)用于想在保留本地分支改動(dòng)的同時(shí)拉取最新的master改動(dòng),然后將我們本地的commit移動(dòng)到最后,例如
feature branch A check out from the origin master
feature branch B check out from the origin master
featureA commit with commit1
featureB commit with commit2 and merge to origin master
featureA rebase origin master
featureA merge to origin master
// 此時(shí) commit1 在git log中會(huì)位于commit2之后,盡管在rebase前 commit1先提交
- squash to 1 commit
方法1:
// X equals to the commits you want to squash
git rebase -i HEAD~[X]
方法2:
git checkout master and pull from origin master
git checkout -b tmp_banch
git merge --squash your_feature_branch
git add and git commit
git push -f origin tmp_branch:your_feature_branch
推薦使用第二種方法,因?yàn)榻柚伺R時(shí)分支,相當(dāng)于做了一層保護(hù)丰歌,就算在這個(gè)臨時(shí)分支上操作錯(cuò)誤也不會(huì)影響到你的feature分支(force push前)