1

I have a repo for automatic report generation. One of the requirements is to put a signature there so I want to make the file with example signature. Then push it to the remote and finally stop to track this file so every new user can change the example but will never push his signature to the remote. I assume that new user is not advanced enough to run (or remember about running) the command: git rm --cached <file>

I would like to apply the changes to all users to realise scenario:

  • new user clones repo
  • the file is in the repo
  • user changes the file
  • no extra command is given
  • git doesn't track the change

Is it possible?

I tried solution given in this topic and they are making the file not available for new users who clone the repo.

@edit I decided to make a workaround. I left tracked example file and added signature file to .gitignore. Now it is the task for software to check if signature file is available and replace the path to it.

piwuch
  • 11
  • 3
  • Is it possible? No not really. It seems your trying to use git to do something it's not designed to do – Liam Apr 06 '23 at 11:01
  • Does this answer your question? [How do I make Git forget about a file that was tracked, but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – Liam Apr 06 '23 at 11:01
  • I already linked this topic in my post. In this solution you don't recevie example file when you clone. I think I will use it anyway and provide the example in a different file. – piwuch Apr 06 '23 at 11:05
  • Just be wary of all the suggestions to use `--assume-unchanged`: it was a fashionable suggestion long ago because it appeared to do the expected thing, but it is ***NOT*** the correct solution. Look for `--skip-worktree` instead. – j6t Apr 06 '23 at 11:08
  • The usual solution for this is to define an optional file that's loaded (either in addition or instead of the default) if it's present and put that file name in the `.gitignore`. Users can then copy the original as a template. – Joachim Sauer Apr 06 '23 at 11:15
  • @j6t Yes, I have documented said "wariness" in the "dissuade users from trying to ignore tracked files" section of [my (revised in 2020) 2014 answer](https://stackoverflow.com/a/23806990/6309). `--skip-worktree` *and* `--assume-unchanged` are both discouraged. – VonC Apr 06 '23 at 11:24

1 Answers1

0

I usually set up a template repository (that you can clone, but cannot push to), with a config.tpl (template file with placeholder values) versioned.

You can then include in that project a build script which will:

  • check if 'config' exists
  • will prompt for your signature if it does not
  • will generate the config file (already present in .gitignore of the repository)

The dame script can also rename the remote origin to upstream, and set origin to a repository you can push to, if need be.

But the basic idea is:

Your users need to perform some operation when cloning/using your repository. It is best if those operations are provided and done through a script, part of the versioned source code of your project.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250