How to tell Git to temporarily ignore changes to a file

01kg - Apr 29 - - Dev Community

WHAT & WHY

I have a config.toml file.

In my local dev env, I have to change SERVER option value from 0.0.0.0 to localhost. I do not wanna include this change in my commit to prevent affecting prod env.

HOW

You can prevent this change from being included in your commit by using the git update-index --assume-unchanged command. This command tells Git to temporarily ignore changes to a file.

Here's how you can do it:

This will prevent Git from tracking changes to the config.toml file. When you're ready to track changes again, you can use the --no-assume-unchanged option:

git update-index --assume-unchanged config.toml

Remember, this is a local operation. Other developers working on the project will still see changes to the file unless they also run the --assume-unchanged command.

git update-index --no-assume-unchanged config.toml

As a best practice, consider using environment variables for configuration settings that change between environments. This way, you can keep the same code in all environments but change the behavior based on the environment variables.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .