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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay