git update-index --assume-unchanged not working for me
Asked Answered
D

2

12

I am in a project building a web app. We use Git for version control and Gulp for task automation. I would like to temporarily ignore files to a certain folder, the build folder. We tend to commit changes to that folder at the end of the day (or at the end of a coding session).

After some research I found the following command to start ignoring changes to a file:
$ git update-index --assume-unchanged path/to/file

When I run that code to ignore the build folder I see on the terminal: Ignoring path build/

But it still shows changes not staged for that folder so that I have to run git checkout -- build/ before each commit.

What am I doing wrong?

I am using git 2.9.3 on a PC with elementary OS (Ubuntu-based distro).

Dicentra answered 19/9, 2016 at 20:42 Comment(2)
I personally add a .gitignore file to any directory whose contents I want to ignore. In the .gitignore file, adding " ./* " ignores all files in that directory. Also, something like " ./somedir/* " will ignore anything in the subdirectory /firstdir/somedir but still stage any other changes under /firstdir/. Not quite the automatic process you may be wanting, but that's how I've done it. Hope it helps somehow – Troika
@Troika Thanks. But I am looking for an alternative without using .gitignore. – Dicentra
R
28

You're not supposed to change the file with that bit.

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.

It's intended to save time on big projects.

This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

I think you're looking for --[no-]skip-worktree

When one of these flags is specified, the object name recorded for the paths are not updated. Instead, these options set and unset the "skip-worktree" bit for the paths.

Usage:

git update-index --skip-worktree <file>

Start tracking again:

git update-index --no-skip-worktree <file>

You might forget what you have skipped, so I have an alias created:

[alias]
    skipped = !git ls-files -v | grep --color "^S"
Radie answered 19/9, 2016 at 22:26 Comment(3)
I have tried the above and assume unchanged but nothing works, It gives me this error always error: Your local changes to the following files would be overwritten by merge: the only option i see is to delete the file and save it somewhere then only it allows me to pull... Please help – Boldface
πŸš€ git update-index --skip-worktree <file> works like a charm! Thanks boss. – Lepidus
I tried both, --assume-unchanged and --skip-worktree. Both commands succeeded but have no effect. git status still reports the folder I want to remove from the list of untracked files as untracked. – Hydromancy
T
-2

We can use

git update-index --assume-unchanged path/to/file

to start ignoring changes to a file and

git update-index --no-assume-unchanged path/to/file

to track file again

Throat answered 27/4, 2022 at 16:2 Comment(1)
I don't believe this is an answer to the question. The OP was having trouble with the first command you listed and the second command isn't a solution to their problem, it only details how to undone the first. The accepted answer explains how --assume-unchanged isn't what the OP should use for their intended purpose. – Jereme

© 2022 - 2024 β€” McMap. All rights reserved.