Skip file changes tracking in git

So, you’re changing this one file for local development purposes only. Maybe it’s config, maybe some source file, but one thing is certain - you don’t want those changes to be committed. And what’s worse, .gitignore doesn’t work.
Yeah, .gitignore works only for files not tracked by git yet. So if there’s a config.ex file, which is a part of the project, and you don’t want to rebuild the repo from the foundation (which is rather a bad idea), then you probably want to reach for this one simple trick:
$ git update-index --skip-worktree config/config.exs
From git docs:
Skip-worktree bit can be defined in one (long) sentence: Tell git to avoid writing the file to the working directory when reasonably possible, and treat the file as unchanged when it is not present in the working directory.
Neither git status, git add . nor your IDE source control visualization should bother you anymore.
Ahh, and remember two more commands if you don’t want to google them later madly:
-
This one shows all the files you marked with the
--skip-worktreeflag
$ git ls-files -v . | grep ^S
> S config/config.exs
- And that’s how you tell git to remove the flag:
$ git update-index --no-skip-worktree config/config.exs
Happy hacking!
Work with a team that keeps learning and building better software every day.
Related posts
Dive deeper into this topic with these related posts
You might also like
Discover more content from this category
There are a bunch of operations you may want to perform before the rendered response in conn is sent to the client, such as minification. In this post I'll show you how to do it easily.
Nowadays, with an ever-growing number of web services, we tend to overload Web apps with external resources. As a result, it decreases page load speed and affects SEO score. There is a pretty easy solution for that.
So you don’t know what’s the type of struct you’re passing somewhere? Maybe it can be one of few types and you have to distinguish them? Or any other reason… But it’s about checking the struct type. Just use one of the coolest Elixir features - pattern matching!
