DEV Community

01kg
01kg

Posted on

How to tell Git to temporarily ignore changes to a file

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.

Top comments (0)