To be clear right up front, since there are many similar-sounding questions around: I DON'T want to track the file.
My use case is that I have a "template" file that developers need to fill in with information. I don't want developers to go committing their changes to this file - they get the file on clone, make their own local changes, and those changes are just that: local. However, I'm not really sure how to get the file into my repo in the first place. Also, I might want to make occasional changes to the template file, but I'd prefer that I have to jump through hoops to do so, so that neither I nor anyone else accidentally commits their secret info.
How can I make commits to an un-tracked file in a git repo?
CodePudding user response:
Take a look at this SO question and the referenced github link as it may help address what you are wanting to accomplish.
How do I stop Git from tracking any changes to a file from this commit forward?
https://help.github.com/articles/ignoring-files#ignoring-versioned-files
CodePudding user response:
Git only allows you to commit files that you track. Tracking a file means, specifically, making Git care about it for commits. If the file is not tracked, then it cannot be committed.
If your goal is to create a template file that people then fill in, then create the template file in a different location from the one where it needs to exist when in use, and use a script to fill it in and copy it to the right location. Then, ignore the path for the modified file. That way, nobody will accidentally commit their file because it's ignored.
What many people try to do is ignore changes to tracked files using some variant of git update-index
. The Git FAQ is clear that doesn't work and shouldn't be done. Instead, the Git FAQ recommends the approach I mentioned above, where you create a template file in a different location and ignore the modified file.