如何清理提交树中未使用的侧枝? [英] How to clean up unused side-branches in your commit trees?

查看:70
本文介绍了如何清理提交树中未使用的侧枝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例(tree,fake-commit-hash,commit message)如何清理未提交的提交树中的未使用的分支(不是真正的git分支)? ,可选[指针]):

  * 0001上次提交[master] [origin / master] [HEAD] 
| * 0002旧的,未使用的合并
| / |
* | 0003一些远程提交
* | 0004另一个提交从远程
| * 0005旧的未使用的提交
| /
* 0006老树

路径0001,0003,0004,0006应该保持不变,但是提交0002和0005没有用,并且没有任何好处。你如何删除提交0002和0005?

解决方案

tarsius 在回答另一个问题中写道:


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


清除reflog,然后清理存储库。首先清理reflog并不总是可行的,因为只要reflog不会过期(这是据我所知,所有悬而未决的提交实际上已经过去了。

所以人们应该确定一个人不再需要所有人。如果真的想保留一些悬而未决的提交,可以:

  git checkout< dangling_commit_id> 
git分支< new_branch_name_of_your_choice>

或使用 git format-patch 将整个提交保存在文本文件中。


How would you clean up unused side-branches in your commit trees (not real git branches)?

Example (tree, fake-commit-hash, commit message, optional [pointers]):

*    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

The path 0001, 0003, 0004, 0006 should stay untouched, but the commits 0002 and 0005 are not useful and aren't doing any good. How do you delete the commits 0002 and 0005?

解决方案

tarsius wrote in an answer to another question:

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

which clears the reflog and then cleans up the repository. Cleaning the reflog at first doesn't always work, because meaningles commits marked by the reflog are kept alive by git-gc as long as the reflog doesn't expire (which is 90 days by default).

After doing this all dangling commits are really gone, as far as I understood. So one should be sure that one really doesn't need all of them anymore. If one really wants to keep some of the dangling commits, one can:

git checkout <dangling_commit_id>
git branch <new_branch_name_of_your_choice>

or use git format-patch to store the whole commit in a text file.

这篇关于如何清理提交树中未使用的侧枝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆