Home > front end >  How to ignore Git changed files?
How to ignore Git changed files?

Time:12-29

I'm working with this setup at the moment. I have 3 changed files that contains mostly environment variables such as Jwt tokens, cloud hosting variables, etc. The changes are mostly of this kind: empty string --> my env variable

I won't ever include them in a commit because, obviously, each member of our team have them different from the other.

But it's pretty annoying in my workflow. I can't stash them permanently because I want that the changes in those 3 files affect my local application. I have to stash them and then stash pop to have them back, every single time I switch branch.

Somehow, I want Git to assume them as changed in every branch of my local repository without keeping them unstaged all the time... Have them untracked even if I changed the files.

Thank you.

CodePudding user response:

You can unstage files from the index using

git reset HEAD -- path/to/file

Just like git add, you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository:

git reset HEAD -- .

Also, for future reference, the output of git status will tell you the commands you need to run to move files from one state to another.

CodePudding user response:

There is no way to ignore tracked files in Git. From the Git FAQ:

Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.

It’s tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.

However, the FAQ has a proposal for your situation:

If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.

  • Related