I have run the following command to ignore watching/tracking a particular directory/file:
git update-index --assume-unchanged <file>
How can I undo this, so that <file>
is watched/tracked again?
Overview. We use git update-index when we want to manually operate on files in Git staging area. This command supports two options that are often misused: –assume-unchanged and –skip-worktree. In this tutorial, we'll see how these two options differ and provide a use case for each.
--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.
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.
To get undo/show dir's/files that are set to assume-unchanged run this:
git update-index --no-assume-unchanged <file>
To get a list of dir's/files that are assume-unchanged
run this:
git ls-files -v|grep '^h'
If this is a command that you use often - you may want to consider having an alias for it as well. Add to your global .gitconfig
:
[alias] hide = update-index --assume-unchanged unhide = update-index --no-assume-unchanged
How to set an alias (if you don't know already):
git config --configLocation alias.aliasName 'command --options'
Example:
git config --global alias.hide 'update-index --assume-unchanged' git config... etc
After saving this to your .gitconfig
, you can run a cleaner command.
git hide myfile.ext
or
git unhide myfile.ext
This git documentation was very helpful.
As per the comments, this is also a helpful alias to find out what files are currently being hidden:
[alias] hidden = ! git ls-files -v | grep '^h' | cut -c3-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With