使用Git跟踪本地忽略的文件 [英] Track local ignored files with Git

查看:71
本文介绍了使用Git跟踪本地忽略的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的仓库中,一些文件和文件夹被忽略。这里感兴趣的是:


  1. 建立输出文件夹,其中包含一些配置文件和外部二进制模块。请注意,这意味着这些感兴趣的文件位于已被忽略的文件夹(bin文件夹)中。

  2. 沿着源代码放置的安装脚本。这些脚本被忽略,因为它们是程序员特定的(例如它们包含到本地机器上的外部库的路径)。
  3. 然而,我会喜欢仅为自己追踪这些文件。主要是清洁后重新创建它们,但也有其他原因。



    如何实现这一目标?






    已经有类似的问题:


    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.

    解决方案

    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跟踪本地忽略的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆