推送到git-hub存储库时自动忽略选定的代码更改 [英] Automatically ignore selected code changes when pushing to a git-hub repository

查看:117
本文介绍了推送到git-hub存储库时自动忽略选定的代码更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我工作的编码项目类型中,通常会有一个人们使用的通用代码库,然后在其之上构建自己的个性化代码。做到这一点的方法是将公共基本代码保存在自己的git-hub存储库中,然后人们可以进行分支和修改。



但是,通用基本代码库,您不想包含您的个性化代码,因此在合并时请注意不要包含它。有没有一种简单的方法来做到这一点,而不必告诉git每次都忽略个性化代码?



如果可能的话,我宁愿避免使用单独的基本代码,用于更改基本代码的具体目的。

方式来检测只是看看它的内容,然后你可以:




  • version only template 文件,这将总是被推送到您的常见内容回购

  • 保留私人价值文件(其中包含正确值的文件,这些文件始终会被您的git回购和从未推送)
  • 版本脚本文件能够获取模板文件,值文件并自动生成正确值的最终结果文件。生成的文件也不会被推送,也可能被git仓库忽略。 自动结帐。

    您可以通过声明内容过滤器驱动程序来实现这一点。





    结帐时,在 smudge 脚本中, 检测内容 <这些'过滤驱动程序'脚本没有名称他们正在过滤的文件),并通过在特定路径中查找值文件来生成正确的内容。


    In the types of coding projects that I work on, there is often a common code base that people use, and then build their own personalized code on top of it. A way to do this would be to keep the common base code in it's own git-hub repository, which people can then fork and modify.

    However, when pushing changes to the common base code repository, you don't want to include your personalized code, so you have to be careful not to include it when merging. Is there a simple way to do this without having to tell git to ignore the personalized code every time?

    If possible, I would prefer to avoid having a separate fork of the base code for the specific purpose of making changes to the base code.

    解决方案

    If the personalization is limited to certain files, with a way to detect just be looking at its content, then you could:

    • version only template files, which would always be pushed to your "common content" repo
    • keep private value files (files with the right values in it, which are always ignored by your git repo and never pushed)
    • version script files able to take a template file, a value file, and generate the right valued end-result file automatically. That generated file wouldn't be pushed either, and would also be ignored by your git repo.

    The idea is to make that generation automatically on checkout.
    You do that by declaring a content filter driver.

    On checkout, in the smudge script, detect the content (those 'filter driver' scripts don't have the name of the files they are filtering) of a your template files, and generate the right content by looking for a value file in a specific path.

    这篇关于推送到git-hub存储库时自动忽略选定的代码更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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