0

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.

DenCowboy
  • 13,884
  • 38
  • 114
  • 210
  • Check the documentation: https://git-scm.com/docs/gitignore It has a lot of helpful information on what you are trying to do – jonathan.ihm Aug 29 '17 at 21:19
  • Possible duplicate : https://stackoverflow.com/questions/3319479/can-i-git-commit-a-file-and-ignore-its-content-changes – zeekhuge Aug 29 '17 at 21:30
  • Is it a configuration file for an application? – CodeCaster Aug 29 '17 at 21:34
  • Possible duplicate of [Committing Machine Specific Configuration Files](https://stackoverflow.com/questions/1396617/committing-machine-specific-configuration-files) – phd Aug 29 '17 at 21:49

3 Answers3

1

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.

Maciej Jureczko
  • 1,560
  • 6
  • 19
  • 23
  • Will this solution apply for all users? I want to find a way that ever clone of a user will result in having a specific file (and they can delete this file or edit this file in their local git) but all this changes to this specific file will be ignored by git. The original remains in the Git repo – DenCowboy Aug 29 '17 at 21:23
  • OK now I understand. My solution applies to your index, so I guess it doesn't solve your problem. There is no in-built solution to this IMO, but I have an idea, I will post a separate answer. – Maciej Jureczko Aug 29 '17 at 21:31
0

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.

Xaqron
  • 29,931
  • 42
  • 140
  • 205
0

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.

Maciej Jureczko
  • 1,560
  • 6
  • 19
  • 23