Track local ignored files with Git

2019-01-27 03:16发布

问题:

In our repository some files and folders are ignored. Of interest here are:

  1. Build output folders which contain (among others) some configuration files and external binary modules. Note that this means that those files of interest are located within already ignored folders ("bin" folders).
  2. Setup scripts which are placed along source code. Those scripts are ignored because they are programmer-specific (for example they contain paths to external libraries on local machine).

Yet I would like to trace those files for myself only. Mostly to recreate them easly after cleaning but there are other reasons as well.

How to achieve that?


There is already a similar question: Track files in local Git repo but ignore in remote. But it is only similar and thus answers proposed there are not applicable here:

  1. My ignored-to-be-tracked files are not placed in a single folder (and it would be impractical to place them so). They are in various places in entire tree. And they are quite sparse by the way. Only a few of them.
  2. Alternative branch cannot be used since I need those files all the time in various branches, not just after switching to that alternative branch.

回答1:

This is a bit hackish, but how about symlinking them from a separate repo into your main project?



回答2:

First, you can add an ignored file to the index and commit it.
You just need to to git add --force -- /path/to/file.

Second, you can add the setup files themselves: they contain private data.
You may consider the template approach, based on a content filter driver which, on checkout, would generate those files (as private non-versioned files) based on:

  • template files (versioned)
  • value files (stored elsewhere, with the right value for each developer's environment)

See for instance "How to keep different content of one file in my local and github repository?"



标签: git gitignore