git rebase / squash to 1 commit

  1. git rebase
    git rebase 我通常會用于想在保留本地分支改動的同時拉取最新的master改動,然后將我們本地的commit移動到最后,例如
 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
// 此時 commit1 在git log中會位于commit2之后,盡管在rebase前 commit1先提交
  1. 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

推薦使用第二種方法,因為借助了臨時分支,相當(dāng)于做了一層保護(hù),就算在這個臨時分支上操作錯誤也不會影響到你的feature分支(force push前)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容