git revert .vs. git reset .vs. git rebase

世有因果知因求果發表於2016-04-07

1. git rervert的工作方式是:將一個老的commit的改動完全找出來,並且在新的tip處執行反操作,最終清除老commit的改動; git revert的應用場景多在對public repo的歷史資訊反悔;

2. git reset <commit>:則通過重寫歷史,將commit之後的所有commits都全部丟棄, 正因為這個特性,git reset往往只存在於本地的commit歷史整理反悔;一旦做了push動作分享到public repo中,我們不應再reset到那個public commit;

 

如git reset, git rebase,以及git commit -amend,我們都不要對已經push到public的commit試圖做修改

 

No one shall rebase a shared branch(只要分支被push到public庫中,我們都不要對這個共享分支做rebase)

相關文章