DenCowboy
DenCowboy

Reputation: 15106

Keep file in git repository and ignore local edits/delete

I have a file which is in my git:

dir1/.thisfile

The content of .thisfile is "Hello" Now I want when users do a git clone they have this file. After that I want the user to delete the file or edit the content of the file locally but I want this to be ignored by git.

How do I achieve this? I have put the file in my .gitignore but when I delete it or change it it is staged. Gitignore seems only to work for files which aren't in my gitrepo.

Upvotes: 0

Views: 75

Answers (3)

Maciej Jureczko
Maciej Jureczko

Reputation: 1598

Generally speaking if you want the files to be ignored globally, they have to be added to global repo git.ignore. I don't see any in-built way of implementing your requirements but you can do it with the following method.

Before pushing the file dir1/.thisfile into your repo, change the name to for e.g.

dir1/.thisfile.model

or

dir1/.thisfile.example

or whatever you like, as long as it is different and meaningful.

Push the file, and then add the original filename (dir1/.thisfile) to global git.ignore. Now the users will always pull that file, but it will clearly be marked with a standout name. If they want to make "production" use out of it (whatever that would be), they need to locally change the name to the original. If they do, no worries, it is ignored already.

Upvotes: 0

Xaqron
Xaqron

Reputation: 30857

If you have the file in repo, no matter if it is mentioned in .gitigore. Every user cloning the repo will get the file but since it is listed on .gitigore they cannot commit it again unless it is removed from .gitigore by them.

So upload the file to repo and the add it to .gitigore. If you want to keep track of local file the check this question.

Upvotes: 0

Maciej Jureczko
Maciej Jureczko

Reputation: 1598

I'm not exactly sure I fully understand you, but if you want to temporarily hide a file from being included in a commit you can use:

git update-index --assume-unchanged <file>

... and the change it back if/when needed with:

git update-index --no-assume-unchanged <file>

Hope this helps.

Upvotes: 1

Related Questions