2012-08-01 11 views
3

你會如何清理你的提交樹中的未使用的側枝(不是真正的git分支)?如何清理提交樹中未使用的側枝?

實施例(樹,假提交散列,提交消息,可選[指針):

* 0001 last commit [master] [origin/master] [HEAD] 
| * 0002 old, unused merge 
|/| 
* | 0003 some remote commits 
* | 0004 another commit from remote 
| * 0005 old, unused commits 
|/ 
* 0006 old tree 

的路徑0001,0003,0004,0006應保持不變,但提交0002和0005是沒有用處,也沒有任何好處。你如何刪除提交0002和0005?

+0

'git gc'可能有幫助:http://www.kernel.org/pub/software/scm/git/docs/git-gc.html – 2012-08-01 09:44:32

+0

可能的重複[列出並刪除沒有分支的Git提交(dangling?)](http://stackoverflow.com/questions/3765234/listing-and-deleting-git-commits-that-are-under-no-branch-dangling) – 2012-08-01 09:52:41

+0

不是100%。標題建議如此,但問題文本實際上更多地討論如何理解和輸出這種提交的狀態。不過,裏面有很多好的建議,可以用來在這裏寫出這個問題的答案。 – erikbwork 2012-08-01 10:23:49

回答

7

tarsius寫道in an answer to another question

git reflog expire --expire=now --all 
git gc --prune=now 

從而清除引用日誌,然後清理倉庫。首先清理reflog並不總是奏效,因爲只要reflog沒有過期(默認爲90天),由reflog標記的意義​​標記提交將保持活動狀態git-gc

做完這一切後,所有懸而未決的提交都真的沒有了,據我瞭解。所以人們應該確定一個人不再需要所有人。如果人真的想保留一些懸掛的承諾,一個可以:

git checkout <dangling_commit_id> 
git branch <new_branch_name_of_your_choice> 

或使用git format-patch存儲整個承諾在文本文件中。