使用Git在本地或主存储库中保存文件的不同版本 [英] Using Git to keep different versions of a file locally vs. in the master repository

查看:133
本文介绍了使用Git在本地或主存储库中保存文件的不同版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP配置文件,我想在本地操作,但在 git commitits 期间忽略这些更改到我的主存储库。我有一个 .gitignore 文件,它曾经忽略这个PHP文件,但不好的事情发生了,现在 config.php 文件不再被忽略,我不记得如何重新忽略它。



我知道SO上的人说要使用git rm --cached< filename> 但我不能为我的生活找出如何不使 git rm ... 继续删除我的config.php文件。

我想知道是否有人可以列出如何忽略我的config.php,以便我可以在本地进行编辑,但这些更改不会添加到回购中。



以下是我的 .gitignore 的全部内容:

  application / config.php 

这里有一些php代码我的 config.php 我想保留本地和进入我的主回购:

  $ config ['base_url'] =http:// localhost /; 
// $ config ['base_url'] =http://mysite.com/; //这是代码,而不是
//http:// localhost,我想保留在我的回购中

删除我的文件:


  1. git rm --cached application / config.php

  2. 更改 application / config.php 文件和另一个文件作为控件)

  3. git commit -m'config.php不应该改变'



    结果: 2个文件已更改,1个插入(+),370个删除( - ) config.php 是370行长)

  4. 解决了我自己的问题。我实际上需要这样做:



    git update-index --assume-unchanged >

    假设在我的问题中指定了.gitignore和config.php文件,那么
    是完整的工作流程:


    1. git update-index --assume-unchanged application / config.php

    2. git add -A
    3. git commit -m'now config.php will be ignored'

    4. git push origin master

    现在 http: // localhost 将保留在本地副本的config.php中, http://my-site.com 将被保留在我的主仓库中的config.php中。


    I have a PHP config file i'd like to manipulate locally but ignore those changes during git commits to my master repository. I had a .gitignore file which used to ignore this PHP file but bad things happen and now the config.php file is no longer being ignored and I can't remember how to re-ignore it.

    I know people on SO say to use git rm --cached <filename> but I can't for the life of me figure out how not to make git rm... keep deleting my config.php file.

    I'm wondering if someone can list how to ignore my config.php such that I can keep editing it locally but these changes don't get added to the repo.

    here's the entire contents of my .gitignore:

    application/config.php
    

    here's some php code in my config.php I'd like to keep local and NOT go in my master repo:

    $config['base_url'] = "http://localhost/";
    //$config['base_url'] = "http://mysite.com/"; // this is the code and NOT
    // "http://localhost" that i'd like to keep in my repo
    

    This is what deletes my file:

    1. git rm --cached application/config.php
    2. make changes to the application/config.php file and another file (as a control)
    3. git commit -m 'config.php shouldn't be changed'

      result: 2 files changed, 1 insertions(+), 370 deletions(-) (config.php is 370 lines long)

    解决方案

    I solved my own problem. I actually need this:

    git update-index --assume-unchanged <filename>

    Assuming the .gitignore and config.php files being specified as above in my question, here's the complete workflow:

    1. git update-index --assume-unchanged application/config.php
    2. git add -A
    3. git commit -m 'now config.php will be ignored'
    4. git push origin master

    Now http://localhost will remain in the config.php on my local copy of the repo and http://my-site.com will be preserved in the config.php in my master repo.

    这篇关于使用Git在本地或主存储库中保存文件的不同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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