可以在分支是其他存储库克隆的地方创建git存储库吗? [英] Can a git repository be created where branches are clones from other repositories?

查看:47
本文介绍了可以在分支是其他存储库克隆的地方创建git存储库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是情况:我继承了两台单独的机器,一台用于开发",另一台是生产机器.问题:它们当然不同步.为了使情况更加合理,我在每台机器上都建立了独立的git存储库,用于存放应用程序目录.

Here is the situation: I have inherited two separate machines, one used for "development" the other is the production machine. The problem: They are of course out of sync. In order to bring some sanity to situation I made independent git repositories of the application directory on each machine.

我现在希望能够比较这些仓库,以便找出它们之间的区别.我的想法是制作第三个存储库,其中包含两个分支,一个来自"dev"计算机的存储库,一个来自"prod"计算机的存储库.

I now wish to be able to compare those repos so I can find out what is different between them. My idea was to make a third repository that contained two branches, one from the repository of the "dev" machine and one from the repository of the "prod" machine.

使用git可以实现这种解决方案吗?

Is this or an equivalent solution possible with git ?

谢谢.

推荐答案

这将使用Git所说的远程" 指的是远程存储库中包含的内容,以便您能够将其拉入自己的分支,将您的分支推入远程存储库,等等.您可以为每个远程存储库设置一个远程另一台计算机,然后在它们之间进行比较以进行比较,如果您要进行本地工作,则可以从这些远程计算机创建一个或多个本地分支.

This would use what Git calls "remotes," which are references to what a remote repository contains in order for you to be able to pull it into your own branch, push your branch into the remote repository, etc. You can set up a remote for each of the other machines, and then diff between them to compare them, and you can create one or more local branches from those remotes if you want to do local work.

针对您的情况,我建议克隆您的开发存储库,这将创建您将要使用的第三个存储库,并自动创建一个指向您的开发的名为 origin 的远程目录存储库(这是您要从推送位置拉到的默认上游"位置的常规名称).然后,为 prod 添加一个遥控器,现在您可以比较它们并在本地使用它们.例如:

What I'd suggest for your situation is cloning your development repository, which will create your third repository that you'll be working in, and automatically create a remote named origin which points to your development repository (this is the conventional name for the default "upstream" place you will be pulling from an pushing to). Then, add a remote for prod, and now you can compare them and work with them locally. For example:

git clone me@dev-server:/path/to/repo.git
cd repo
git remote add prod me@prod-server:/path/to/repo.git
git remote update
git diff origin/master prod/master

这篇关于可以在分支是其他存储库克隆的地方创建git存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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