假設你在Git的git倉庫中工作,並且你有一個好主意。
$ git rm -rf Documentation
$ git commit -m 'Documentation is for the weak'
這會導致以下歷史記錄。 (注:git lol
是非標準的,但非常有用的別名)
$ git lol
* d55a922 (HEAD, master) Documentation is for the weak
* 443d803 (origin/master, origin/HEAD) Merge branch 'maint'
|\
| * 8d44277 (origin/maint) Update draft release notes to 1.8.1.5
| * 6f0c336 Merge branch 'ef/non-ascii-parse-options-error-diag' into maint
| |\
...
給自己一個再調度,在您的新崛起的檢出一個分支提交併恢復那裏。
$ git checkout -b mulligan/delete-all-documentation
$ git revert --no-edit HEAD
現在用
$ git checkout master
,你可以回去工作。
說你添加一個新的承諾高手,那麼你的歷史變成
$ git lola
* b4d76d9 (HEAD, master) Add new feature X
| * 84b0e21 (mulligan/delete-all-documentation) Revert "Documentation is for the weak"
|/
* d55a922 Documentation is for the weak
| * 46b564f (origin/pu) Merge branch 'pc/subtree-add-before-fetch' into pu
...
這不是一個常見的做法。只有當git merge
或git cherry-pick
乾淨利落時,也就是說,如果沒有其他更改已應用於刪除舊功能的代碼,則恢復該功能將非常容易。看看這條路,看看這個規模會有多糟糕。爲了恢復舊功能,開發人員必須篩選一系列分支以找到正確的恢復。 Git有極好的支持搜索歷史,我們從缺乏這些長壽命的mulligan分支是常見的做法。
感謝大聲笑的提示。輝煌! – sfk 2013-03-03 10:02:54