【问题标题】:git: ignore a file on pull from remote1, but push local version to remote2git:忽略从远程1拉取的文件,但将本地版本推送到远程2
【发布时间】:2013-06-30 17:55:31
【问题描述】:

我有 3 个 git 存储库:

  • local:我本地机器上的开发仓库;
  • remote1 用于与其他开发者协作;
  • remote2 是生产服务器。

    1. 我想定期将pullremote1 转到我的local 存储库,并保持一些本地跟踪文件完好无损(即从remote1 获取和合并,但不合并某些本地跟踪文件)。

    2. 另一方面,我想定期将push 发送到remote2,并且我也想推送本地跟踪的文件。

换句话说,我想要file1的以下版本:

  • local: file1 v.1
  • remote1: 文件 1,v.2
  • remote2: 文件 1,v.1

注意:file1 可以是任何东西(.css、.html,甚至 .png)

我尝试了以下方法:

  • .gitignore 一个文件(不起作用,从remote1 拉取后文件再次被跟踪)
  • git pull --no-ff --no-commit remote1 master,然后git checkout --ours file1 根据this(不起作用,file1 变成 v.2)
  • .git/info/excludehere 所述(不起作用,什么都不会被忽略,即使被忽略,file1 也不会被推送到 remote2 然后)

【问题讨论】:

    标签: git gitignore git-pull git-remote git-checkout


    【解决方案1】:

    你可以试试:

    • git update-index --assume-unchanged -- path/to/file1之前remote1拉出,并且
    • git update-index --no-assume-unchanged -- path/to/file1remote1 拉出后。

    (如果不行,也试试git update-index --skip-worktree

    【讨论】:

    • 您能详细说明一下吗?这个命令在下面做什么?可以用同样的方式推送吗?
    • @MartinLee stackoverflow.com/a/13631525/6309。您可以在推送之前删除该选项。
    猜你喜欢
    • 2014-01-13
    • 1970-01-01
    • 2013-06-20
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多