Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 986
kucinghitam Avatar asked Apr 26 '19 04:04

kucinghitam


1 Answers

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" \;
like image 124
VonC Avatar answered Sep 28 '22 05:09

VonC