从git存储库中删除工作文件,以节省空间 [英] Remove working files from git repository, to save space
问题描述
我的磁盘上有许多GitHub项目,但其中许多项目并未处于活动状态。
我想删除当时的工作文件因为它们存储在提交历史记录中,因此我可以在稍后检索它们。
删除文件的最简单方法是 rm -rf *
但它有许多缺点:它不会删除点文件,例如 .gitignore
git status
已删除的文件。我必须研究是否应该提交这些清除,或者如果我刚删除它们以暂时节省空间。什么是快速简单的方法来删除工作文件?如果你使用git 2.5.1或者更高版本,你可以使用裸存储库(open repository)。
,并且使用 git worktree添加/ some / checkout /路径分支
如果您想检查或使用它的内容。 工作树完全可以像标准的git克隆一样工作,期望您在那里运行的所有修改(提交,新分支,标记......)都可以应用到裸副本。
I have a number of GitHub projects on my disk, but many of them are not in active use.
I would like to remove the working files for the time being, because they are stored in the commit history anyway, so I can retrieve them at a later time.
The easiest way to remove the files is rm -rf *
but it has a number of drawbacks:
- It doesn't remove dotfiles such as
.gitignore
- If I come back later,
git status
complains about lots of removed files. I have to work out whether I should commit these removals, or if I had just removed them to temporarily save space.
What is a quick and easy way to remove the working files? And is there a way to do it cleanly?
If you use git 2.5.1 or higher, you can use bare repositories, and use git worktree add /some/checkout/path branch
if you want to inspect or use its content.
The worktree will work exactly as a standard git clone, expect that all modifications you run there (commits, new branches, tags, ...) are applied to the bare clone.
这篇关于从git存储库中删除工作文件,以节省空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!