So it happened a couple of times when I would be working on connected projects that this scenario took place:
Now I was wondering, is it possible to track some files but automatically ignore them when committing ? Think of it as a more lenient version of the .gitignore
where I can choose some files to track while am developing locally, but they would never be committed.
I was thinking I could make a script that unstages those specific files in the then runs the commit. However, is there something I should be paying attention to ? Or perhaps there's already a way my quick search didn't pick up?
What you want here is to enable --skip-worktree
bit for the configuration file.
First, ensure that git tracks the file existence by committing it at least once:
% git add Config.file
% git commit -m 'Configuration added'
Then flip the --skip-worktree
bit:
% git update-index --skip-worktree Config.file
From this point forward all changes you make to the file will be ignored by git.
In order to see the changes and restore the file you can get use of the following git aliases:
[alias]
diffsw = !git update-index --no-skip-worktree $1 && git diff -- $1 && git update-index --skip-worktree $1 && :
restoresw = !git update-index --no-skip-worktree $1 && git restore -- $1 && git update-index --skip-worktree $1 && :
The first one shows the changes of the untracked file and can be used like this:
% git diffsw Config.file
The second one restores the file to the state it was last time commited:
% git restoresw Config.file
P.S. This, however, affects only local repo, you cannot push this bit.