简体   繁体   English

git:忽略来自remote1的文件,但将本地版本推送到remote2

[英]git: ignore a file on pull from remote1, but push local version to remote2

I have 3 git repositories: 我有3个git存储库:

  • local : my development repo on my local machine; local :我在本地机器上的开发代码;
  • remote1 used for collaboration with other developers; remote1用于与其他开发人员合作;
  • remote2 which is a Production server. remote2是一个生产服务器。

    1. I would like to pull regularly from remote1 to my local repo and keep some local tracked files intact (ie fetch and merge from remote1 , but exclude some local tracked files from being merged). 我想定期从remote1 pull我的local仓库并保留一些本地跟踪文件(即从remote1获取和合并,但排除某些本地跟踪文件被合并)。

    2. On the other side, I would like to regularly push to remote2 and I would like local tracked files to be pushed as well. 另一方面,我想定期push送到remote2 ,我也希望push本地跟踪文件。

In other words, I would like to have the following versions of file1 : 换句话说,我想拥有以下版本的file1

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

Note: file1 can be anything (.css, .html, even .png) 注意: file1可以是任何东西(.css,.html,甚至.png)

I have tried the following approaches: 我尝试了以下方法:

  • .gitignore a file (does not work, the file becomes being tracked again after pull from remote1 ) .gitignore一个文件(不起作用,从remote1拉出后再次跟踪文件)
  • git pull --no-ff --no-commit remote1 master , then git checkout --ours file1 according to this (does not work, file1 becomes v.2) git pull --no-ff --no-commit remote1 master ,然后根据这个 git checkout --ours file1 (不起作用,file1变为v.2)
  • .git/info/exclude as described here (does not work, nothing is ignored and even if it is ignored, file1 will not be pushed to remote2 then) .git/info/exclude所描述的位置 (不工作,没有被忽略,即使它被忽略, file1将不会推到remote2然后)

You could try to a: 你可以尝试:

  • git update-index --assume-unchanged -- path/to/file1 before pulling from remote1 , and git update-index --assume-unchanged -- path/to/file1remote1拉出之前的 git update-index --assume-unchanged -- path/to/file1 ,和
  • git update-index --no-assume-unchanged -- path/to/file1 just after pulling from remote1 . 刚从remote1拉出后, git update-index --no-assume-unchanged -- path/to/file1

(If that doesn't work, try also git update-index --skip-worktree ) (如果这不起作用,请尝试git update-index --skip-worktree

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM