特定目标文件夹的git filter-branch rm通配符 [英] git filter-branch rm wildcard for a specific target folder

查看:110
本文介绍了特定目标文件夹的git filter-branch rm通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的git信息库下有一个名为packages的目录(此处为 root/packages/files ),其他子文件夹中的目录也具有相同的名称( root/directory1/packages/files这里).我想确保删除前者中的所有内容,而后者保持原样.这个命令会匹配吗?如果是,我该怎么做才能确保git rm仅将 root/packages/所有文件作为目标?

I have a directory named packages immediately under my git repository (root/packages/files here) and another with the same name in some other subfolder(root/directory1/packages/files here). I want to make sure that everything in the former is removed and the latter stays as is. Is this command going to match both? If yes, what can I do to make sure only root/packages/all files is targeted by git rm?

git filter-branch --index-filter 'git rm --cached --ignore-unmatch packages/*' --prune-empty HEAD

推荐答案

由于这是--index-filter而不是--tree-filter,因此最明智的做法是保护外壳字符*不受外壳影响. 1 即:

Because this is an --index-filter and not a --tree-filter, it's wisest to protect the glob character * from the shell.1 That is:

git filter-branch \
    --index-filter 'git rm --cached --ignore-unmatch "packages/*"' \
    ...

例如

. (在--tree-filter中,*将以通常的预期方式运行.)这将* glob扩展扩展为Git,这将仅匹配存储在索引中的名为packages/的目录中的名称. (这就是您要说的.)

for instance. (In a --tree-filter, * will behave in the usual expected way.) This leaves the * glob expansion up to Git, which will match only names in the directory named packages/ as stored in the index. (That's what you say you want.)

作为 git rm文档注释,这也将匹配目录名称.由于缺少-r,它不会删除这些目录,但仍会与它们匹配.如果没有这样的目录,就不会有问题.

As the git rm documentation notes, this will match directory names as well. It won't remove those directories, due to the lack of -r, but it will still match them. If there are no such directories this will not be an issue.

1 filter-branch命令在一个临时目录中运行每个过滤器,因此大多数设置下的大多数外壳最终都将*保留为未扩展状态,并且仍然可以执行正确的操作.

1The filter-branch command runs each filter in a temporary directory, so most shells under most settings wind up leaving the * un-expanded and do the right thing anyway.

请注意,如果您使用的是--tree-filter,则临时目录中包含要过滤的树的副本.否则为空.

Note that if you are using a --tree-filter, the temporary directory has a copy of the tree being filtered. Otherwise, it is empty.

这篇关于特定目标文件夹的git filter-branch rm通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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