DEV Community

Stefano
Stefano

Posted on

3 2

How to change a file locally without commit it on Git

Scenario

I wanted to freeze a file in git, so that when someone commits, this file is not updated.
The scenario was something like that: I need an ENV variable that usually will be available only on CI/CD to take the right token but on the local side I don't need it.

The Problem

So I want a file that will be on my repository, and will be versioned but I want to change it on the local side and not commit it (I can skip it every time without include it on git add but it's so boring and in long term will not work).
I tried a different hack solution like .gitignore but it did not work.
So I read some documentation and I discovered the update-index option on git.

How update-index works

With this command:
git update-index --assume-unchanged <file>
Are you basically changing the assume unchanged bit and are you forcing Git to pretend it never changes.
In this way Git will exclude this file from any tracking, so you can modify it on the local side and basically forget it.

If you want to came back to the "normal version" u can easily exec this command:
git update-index --no-assume-unchanged <file>
and everything will come back like before.

If u want to check what kind of files are with this active flag you can easily run:
git ls-files -v
Files where the flag is --assume-changed have H, --assume-unchanged is h.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

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

Okay