14

假设我有这个已经被 git 跟踪的工作树。

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

我想在里面标记每个跟踪的文件,parent以便 git 不再跟踪对它们所做的任何更改,最终将包括somefile.txt, anotherfile.txt, file1.txt, file2.txt, file3.txt.

.gitignore仅适用于未跟踪的文件,所以我使用--skip-worktree.

我试过了:

1.

git update-index --skip-worktree parent/

给了我Ignoring path parent/,但是当我检查时git ls-files -v,它仍然显示我想跳过的文件仍然被跟踪。

2.

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

它给了我fatal: Unable to mark file parent/child1,因此它无法标记目录及其包含的任何内容。

如果不手动添加我里面的每个文件,我怎么能做到这一点parent

4

1 回答 1

9

与假设未更改类似,您需要将此命令应用于文件夹中的所有文件:

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

(没有“递归”选项git update-index

编辑:

不要忘记首先cd进入您想要的目录skip,然后运行上述命令。

而且,如果您想撤消它,只需执行相反的操作:

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --no-skip-worktree" \;
于 2019-04-26T04:49:43.397 回答