directory structure - How can I use git-rm and file globbing to remove files from certain directories but not subdirectories of those directories? -
the scenario
i'm trying remove files entire history of git repository. share couple of common criteria:
- they have "settings" in file name. may have various prefixes , suffixes, though.
- they two levels deep inside directory in file tree. names of second level directories vary. there settings files deeper in file tree should not removed.
here, then, example of file tree:
root-directory/ |-> apples/ | |-> bad-settings-alpha.txt | |-> bad-settings-beta.txt | |-> oranges/ | |-> bad-settings-gamma.txt | |-> bad-settings-delta.txt | |-> navels/ | |-> good-settings.txt | |-> good-settings.txt i need filter out bad-settings files while keeping good-settings files.
my approach
so, using a tutorial provided github, in conjunction manpage git-rm, crafted command (split across 2 lines):
git filter-branch -f --index-filter 'git rm --dry-run --cached \ --ignore-unmatch root-directory/*/*settings*.txt' --prune-empty -- --all of particular note here file glob used: root-directory/*/*settings*.txt. if use file glob ls, list of files want remove. so, should work, right?
apparently not. if run command glob, takes out settings files in levels deeper 2 well. in file tree example above, means root-directory/oranges/navels/good-settings.php nuked.
i've tried solve on own, trying variations on file glob , using wonderful --dry-run option git-rm. nothing seemed work--all figure out how change file tree depth @ started removing settings files.
i did find 1 thing seemed extremely relevant problem. in manpage git-rm, there example:
git rm documentation/\*.txt removes *.txt files index under documentation directory , of subdirectories. note asterisk * quoted shell in example; lets git, , not shell, expand pathnames of files , subdirectories under documentation/ directory. "removes all...files index under the...directory , of subdirectories" consistent what's happening. what's interesting mention of quoted asterisk. understand lets git-rm handle file glob expansion opposed bash. okay. leaves these questions:
- why want that?
- i'm not quoting asterisks,
bashshould doing expansion. if that's true, , file glob worksls, why isn't workinggit-rm?
i've seen example directly beneath 1 above, , seems i'm trying do. , yet, not happen me, or else not here. seem confirm want file expansion bash, though.
why not use find show 2 level deep files:
find . -maxdepth 2 -mindepth 2 -type f -name "bad-settings*" this give list of bad-settings of 2 level deep directores. can them pipe them git rm via xargs:
find . -maxdepth 2 -mindepth 2 -type f -name "bad-settings*" | xargs git rm
Comments
Post a Comment