git只清除跟踪的文件 [英] git clean only tracked files

查看:63
本文介绍了git只清除跟踪的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常不寻常的用例,但是我想从git repo中删除所有跟踪的文件.是的,跟踪的文件,而不是未跟踪的文件.

It is an extremely unusual use case, but I would like to remove all tracked files from git repo. Yes, the tracked files, not the untracked ones.

我有大量的代码生成文件,其中有些是二进制文件,有些是文本文件.我希望能够跟踪文本生成文件的历史记录.我有忽略列表集,等等.问题是,下次运行生成过程时,它将更改所需的文件,添加新文件,但不会删除不再生成的旧文件.删除整个工作树就可以了,但是它也会删除二进制文件和其他已经存在的文件,我不想这样做.

I have a big set of code generation files, some of them binary some of them text files. I would like to be able to track the history of the text generated files. I have the ignore list set, etc. The problem is that the next time I run the generation process it will change the needed files, add the new ones, but it is not going to remove old ones that are not generated anymore. Deleting the whole work-tree will do, but it will also remove the binary and other files that are already there, and I do not want to do that.

如果我可以选择使用git清除仅跟踪的文件,那么最好使用已经准备好的复杂.gitignore文件来区分文件,但是我在文档中什么都看不到.

If I have the option to use git to clean only the files that are tracked will be the best using already prepared complex .gitignore file to distinguish the files, but I do not see anything in the documentation.

是否有一个棘手的选项,如何从工作树中删除所有被跟踪的文件.

Is there tricky or not an option how to delete from the work-tree all files that are tracked.

推荐答案

如果要删除 master 分支中受版本控制的每个文件,则可以尝试:

If you wanted to remove every file under version control in the master branch, then you could try:

git ls-tree -r -z master --name-only | xargs -0 git rm

管道前的命令的第一部分以递归方式查找 master 中所有已版本化的文件,而 git rm 将从远程存储库中删除每个文件.

The first part of the command before the pipe recursively finds all files in master which are versioned, and the git rm removes each one from the remote repository.

git rm< file> 从远程存储库中删除文件.

git rm <file> removes a file from being tracked by the remote repository.

这篇关于git只清除跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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