kuc*_*tam 12 git git-skip-worktree
假设我有一个已经被 git 跟踪的工作树。
.
??? parent
? ??? child1
? | ??? file1.txt
? ??? child2
? | ??? file2.txt
? | ??? grandchild
? | ??? file3.txt
? ??? somefile.txt
? ??? anotherfile.txt
|
Run Code Online (Sandbox Code Playgroud)
我想标记其中的每个跟踪文件,parent
以便 git 不再跟踪对它们所做的任何更改,最终将包括somefile.txt
, anotherfile.txt
, file1.txt
, file2.txt
, file3.txt
.
.gitignore
仅适用于未跟踪的文件,所以我使用--skip-worktree
.
我试过:
1.
git update-index --skip-worktree parent/
Run Code Online (Sandbox Code Playgroud)
给了我,Ignoring path parent/
但是当我检查时git ls-files -v
,它仍然显示我想跳过的文件仍在跟踪中。
2.
git update-index --skip-worktree parent/*
Run Code Online (Sandbox Code Playgroud)
它给了我fatal: Unable to mark file parent/child1
所以它不能标记目录及其包含的任何内容。
如何在不手动添加内部的每个文件的情况下执行此操作parent
?
与假设未更改类似,您需要将此命令应用于文件夹中的所有文件:
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && pwd && git ls-files -z ${pwd} | xargs -0 git update-index --skip-worktree" \;
Run Code Online (Sandbox Code Playgroud)
(没有“递归”选项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" \;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3396 次 |
最近记录: |