Reputation: 51
I want to ignore a specific change in my file, but I can only find suggestions to ignore an entire file. Or is there a better way to do so?
The problem is that if I make a change to that ignored file, I cannot commit it without committing the change that should be ignored.
I also work with Visual Studio Code. Is there a way to do that using the editor?
Upvotes: 0
Views: 3256
Reputation: 35731
I know you asked for a Git based answer, but I don't think that is your real problem!
The key to solving this problem is to load and manage environmental variables based on on different environments that you might be running: testing, production, development, features etc.
There are existing tools out there like: Figaro, and dotenv which can solve your problem - and if you are not using Ruby, or Rails, you will likely find equivalents of the above for your specific language/platform.
Upvotes: 1
Reputation: 13327
I can only find suggestions to ignore an entire file
Although other answers solve your particular problem better, the answer to the question, is it possible to ignore some portions of the file in the same way you can ignore entire files in .gitignore? is no.
You can choose to ignore or add certain changes to a particular file with git --patch -- fileName.txt
, but you will have to do it every time you stage changes. There's no way to mark some lines in the file as ignored forever the same way .gitignore
marks entire files.
Upvotes: 0
Reputation: 20601
A common way to solve this, is to have your application code always read your "base config file" and try to read an "override config file". The latter overrides every config option found and falls back to the base for options not existing in the "override".
The base config file is checked in, the other is not.
Upvotes: 2
Reputation: 1510
You can discard in the left pane file options:
And then make your changes in the file.
You can also do a git stash
, then make your changes, commit them and discard the old changes with git stash drop
.
Upvotes: 0
Reputation: 28868
git works on file level in the repository, not change level.
Upvotes: 0