Temporarily hide some modified files in git

Whenever I do a work task, I create a local branch in git, then I need to modify a bunch of config files (mainly containing database connection strings) to set the local environment before actually working. I don't want to push these changes to the repository later after I finish my task.

Actually, I would rather filter them out when looking at modified files ( git status

).

I could make the first commit on my local branch and return it before pushing. But there is a chance that I will forget it. Is there a better way to do this?

+3


source to share


2 answers


The most recommended solution is to use:

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

      

Documentation :

- [no-] worktree skip

When one of these flags is specified, the object name recorded for paths is not updated. Instead, these options set and disable the "skip-worktree" bit for paths. See the "Skip-worktree Bit" section below for more information.

And the skip-worktree bit :



Skip-worktree bit

The Skip-worktree bit can be specified in one (long) sentence: when reading a record, if it is marked as skip-worktree, then Git pretends that its working directory version has been updated and reads the indexed version instead.

To clarify, "read" means checking for the existence of a file, reading the attributes of a file or the contents of a file. The working directory version may or may not be present. If present, its contents may or may not match the index version. This bit is not affected by recording, content security is still a top priority. Note that Git can update the working directory file that is marked as skip-worktree if safe to do so (for example, the working directory version matches the index version)

Although this bit is like a bit-bit that does not take on a value, its purpose is different from bits with a fixed value. Skip-worktree also takes precedence over received-unchanged bit when both are set.

The flag --assume-unchanged

is for performance reasons, while it --skip-worktree

is for when you change a file and want Git to skip over it.

To undo use:

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

      

+3


source


To temporarily ignore changes in a specific file, you can do this:

git update-index --assume-unchanged <file>

      



If you want to track changes again, you just need to run:

git update-index --no-assume-unchanged <file>

      

+3


source







All Articles