Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 两个远程存储库,不同的文件夹_Git_Git Remote - Fatal编程技术网

Git 两个远程存储库,不同的文件夹

Git 两个远程存储库,不同的文件夹,git,git-remote,Git,Git Remote,我有一个git存储库: 存储库A: config view1.yml view2.yml public css/ styles.css js/ scripts.js index.html 我想添加另一个远程存储库,但只跟踪公用文件夹的内容,例如: 存储库B: css/ styles.css js/ scripts.js index.html 我怎么能在本地做到这一点?使用git remote add?如果所有内容都在一个要导出的目录下,并且确实要忽

我有一个git存储库:

存储库A:

config
  view1.yml
  view2.yml
public
  css/
    styles.css
  js/
    scripts.js
  index.html
我想添加另一个远程存储库,但只跟踪公用文件夹的内容,例如:

存储库B:

css/
  styles.css
js/
  scripts.js
index.html

我怎么能在本地做到这一点?使用git remote add?

如果所有内容都在一个要导出的目录下,并且确实要忽略其他内容,则可以使用git filter branch向下过滤分支,然后将生成的分支推送到Repo B

从您感兴趣的分支的顶端开始,假设您只想保留对dir“public”和下面的更改:

git checkout -b nameOfPublicBranch
// Create a new branch where you want to start to filter

git filter-branch -f --subdirectory-filter public
// This filters your branch down to commits that modified public (and below)

git push repoB nameOfPublicBranch
// now export to repoB just this stuff that you wanted on your branch nameOfPublicBranch

git checkout <yourOldBranchName>
// get back to your old branch
git checkout-b公共广播电台的名称
//创建要开始筛选的新分支
git筛选器分支-f--子目录筛选器公用
//这会将您的分支向下过滤,以提交修改后的public(及以下)
git push REPORB公共广播电台名称
//现在导出到repoB,就是您希望在PublicBranch的分支名称上显示的内容
git签出
//回到你的老分部去
如果您想将提交压缩为PublicBranch分支名称上的一个,那么在推送它之前对它进行一次重基压缩


可能还有很多其他方法可以实现这一点,其中一种可能是使用子模块,这种方法可能会出现意外问题(重写历史)。

也许您应该使用gitignore(它告诉git忽略文件,不要跟踪它们)和以下内容(未测试):

如果已经跟踪了文件,则需要在设置gitignore之前运行
git rm--cached

如果你想了解更多关于gitignore的信息,也许你想阅读git教程。

看看。从他们的文档中,它解释了以下内容:

…子树允许子项目包含在 主项目,可选地包括子项目的整个 历史

例如,您可以将库的源代码作为 应用程序的子目录

我将在某处创建新的裸存储库(
gitinit--bare
),并执行子树
split
命令来“分支”公用文件夹的历史记录。然后我会将此信息推送到您的其他存储库。这个例子可以在上面链接的文档中看到


git init——裸
git子树拆分--prefix=lib--annotate=“(拆分)”-b拆分
git推送拆分:主
看一看
*
!/css
!/js
<go to the new location> 
git init --bare  
git subtree split --prefix=lib --annotate="(split)" -b split   
git push <new-repo> split:master