git update-index

At times, you may find yourself needing to modify certain files temporarily to facilitate running code or testing locally. However, you may wish to avoid inadvertently pushing these changes to your Git repository. In such situations, Git offers a solution by allowing you to instruct it to disregard modifications in specific files, such as template.yml, using the command git update-index –assume-unchanged filepath. This approach is particularly useful when you realize that these changes are only intended to facilitate local development or testing and should not be included in your version control history.

Sometimes you have to edit some files to run something on your local machine but then you have to undo them because you don’t want to push them to the git.

You can view the files that you’ve added to git ignore list by running:

git ls-files -v | grep '^[a-z]'

Once you are done, you can remove file from ‘assume-unchanged’, so you can just run:

git update-index --no-assume-unchanged filepath

This can be a bit tiresome if you have to do it for all files, so with bit of shell magic you can do something like this:

git ls-files -v | grep '^[a-z]' | awk '{print $2}' | xargs -I {} git update-index --no-assume-unchanged {}