elvisTeixeira
elvisTeixeira

Reputation: 21

How to keep a version of a file fixed on github

I want to upload a project to GitHub, but one of the source files in the project must be unchanged, that is, the first version on GitHub must stay the same, regardless the modifications that developers make on their local file versions. Do any one realize how to do that?

Upvotes: 2

Views: 62

Answers (1)

tbekolay
tbekolay

Reputation: 18547

Option 1: ignore it locally

Once you've added a file, git tracks it, even if it is in .gitignore. You can do things locally to ensure that you won't accidentally commit it, such as

git update-index --assume-unchanged path/to/file.txt

However, you would have to ensure that all of your collaborators also do this, which is difficult.

Option 2: make a template

Instead, I think a better strategy is to make a "template" that people can use to start off their often changing file.

For example, let's say that the file is a configuration file, local.conf. This file contains things like passwords and directories that are specific to a machine, so you wouldn't want to add those things to a repository. But, in order to have a valid local.conf file, you need to know the structure of that file.

Instead of committing local.conf and letting people change it, make a template file local.conf.template. Add local.conf to .gitignore, so that everyone's local.conf will never be committed. Then, in your README, instruct your collaborators to do

cp local.conf.template local.conf

and edit it from there.

Upvotes: 2

Related Questions