Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git update-index --assume-unchanged on directory

People also ask

What is assume unchanged in git?

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git.

What is Skip Worktree?

--skip-worktree explained: This allows you to make changes to a file that you don't want to be pushed to upstream. Use this option as already shown above.


git update-index wants the file names on its command line, not on its standard input.

Step 1:

cd into the folder you want to assume is unchanged

Step 2:

You can do either this:

git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')

or

git ls-files | tr '\n' ' ' | xargs git update-index --assume-unchanged

Although, with either case, file names with spaces will be problematic. If you have those, you can use this:

git ls-files -z | xargs -0 git update-index --assume-unchanged

Edit: incorporated input from @MatthewScharley regarding git ls-files -z.

Windows Commands

Note: If you're on windows, use Git Bash to run these commands


The find command from GNU Findutils has a -exec option which removes most of the hassle of using xargs, although its syntax is a little special. It does however deal perfectly with filenames with spaces.

This command will get git to assume all files in and under the listed directory are unchanged:

find path/to/dir -type f -exec git update-index --assume-unchanged '{}' \;

Find takes every argument after -exec until ; (which you have to escape lest your shell eats it) and runs it once for each file found, while replacing {} (again, single quoted so your shell won't eat it) with the found file's name.

Using find's matching criteria (maximum recursion depth, whether the match is a file or is a directory, whether the filename matches an expression) and -exec you can do all sort of powerful things.

Not sure about other implementations of the find command. YMMV.


Add the directory name to .git/info/exclude. This works for untracked files.


Yeap,

git update-index --assume-unchanged

works with files only, not with directories. I think, one of faster ways:

cd dir
ls | xargs -l git update-index --assume-unchanged