Git Skip Worktree on All Tracked Files inside Directory and its Subdirectories

本小妞迷上赌 提交于 2020-01-01 16:33:34

问题


Let's say I have this worktree that has already been tracked by git.

.
├── parent
│   ├── child1
│   |    └── file1.txt
│   ├── child2
│   |    ├── file2.txt
│   |    └── grandchild
│   |         └── file3.txt
│   ├── somefile.txt
│   └── anotherfile.txt
|

I want to mark every tracked files inside parentso that any changes made to them woudln't be tracked by git anymore, which in the end would include somefile.txt, anotherfile.txt, file1.txt, file2.txt, file3.txt.

.gitignore only works on untracked files so I'm using --skip-worktree.

I tried:

1.

git update-index --skip-worktree parent/

Gave me Ignoring path parent/ but when I check git ls-files -v, it still shows me that the files I want to skip are still tracked.

2.

git update-index --skip-worktree parent/*

It gave me fatal: Unable to mark file parent/child1 so it cannot mark a directory and anything it contains.

How can I do this without manually add every file I have inside parent?


回答1:


Similarly to assume-unchanged, you need to apply this command to all files within a folder:

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --skip-worktree" \;

(there is no "recursive" option to git update-index)

EDITED:

Don't forget to cd into the directory that you want to skip first, then run the above commands.

And, if you want to undo it, just do the opposites with this:

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --no-skip-worktree" \;


来源:https://stackoverflow.com/questions/55860925/git-skip-worktree-on-all-tracked-files-inside-directory-and-its-subdirectories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!