如何在git中设置临时存储库? [英] How do I setup a staging repository in git?

查看:124
本文介绍了如何在git中设置临时存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个存储库[B],在一个名为x_master的分支中跟踪远程存储库的主[A]。它自己的主人也应该在最初创建时成为克隆人,其他人[Devs]可以克隆并推送更改。



偶尔,由于A,I将需要能够将它们合并到B的x_master(如果我明白这一点,它应该是快进的,因为它们将是B上x_master分支的唯一更改),然后能够合并它们变成B的主人,因此变成任何克隆B的主人时他们拉。



我在概念上想要的是这样的:

  master x_master 
[A]< ---------> [B]< -------> [Dev2]
^ -------> [Dev1]
master

最后,我需要将B的主变更推送到当所有的开发工作完成时,A的主人,但是会有变化发生在A中,需要合并到B中。b / b


  • 我如何设置这个?


  • 这个设置是否有意义?



我尝试了各种clone --mirror,branch --track,并且似乎没有在A和B的推拉中正确地获取更改。

解决方案

我确信有一个捷径,但我倾向于使用基本命令。在任何情况下,为 B 设置存储库:

  $ cd repo_B 
$ git init --bare
$ git remote add upstream URL_FOR_REPO_A
$ git fetch upstream + master:refs / heads / x_master
$ git branch master x_master

当上游存储库被修改时,您需要在裸仓库 1 中提取这些更改:

  $ git fetch upstream + master:refs / heads / x_master 

这会覆盖 2 x_master 中的所有可能更改,所以你最好单独离开那个分支。 :)



您将要将 x_master 中的上行变更合并到 master when / if A改变。不幸的是,在这个阶段可能会有冲突,因此必须使用裸仓库的克隆来完成。简单地复制B库(到本地或远程位置),并将 x_master 合并到 master 中,解决冲突,并推回。



最后的任务是将开发完成于 master 到存储库A.以两种方式完成。第一种方法是直接将B的主服务器推送到存储库A.这可以通过运行来完成:

  $ git push upstream 

。另一种方法是从 master x_master 使用第三个存储库:

  $ git clone URL_FOR_REPO_A 
$ cd repoDir
$ git remote add dev URL_FOR_REPO_B
$ git fetch dev
$ git branch --track master_b dev / master
$ git merge master_b
$<解决冲突(如果有的话)>
$ git push origin master






注意1



完成后,您可以配置远程只在默认情况下获取该分支:

  $ git configure branch.upstream.fetch + master:refs / heads / x_master 

使用 - 添加,您甚至可以添加更多分支来获取:

   

现在,fetch可以正常工作,不需要refspecs:

  $ git fetch upstream 






注2



code> master repo_B ,您可以使用 pre-receive code>或 update


I want to create a repository [B] that tracks a remote repository's master [A] in a branch called x_master. Its own master should also be a clone at the initial creation time that others [Devs] can clone and push changes into.

Occasionally, as there are changes in A, I will need to be able to pull them down and merge them into B's x_master (which, if I understand this, should be a fast-forward as they will be the only changes in x_master branch on B), and then be able to merge those changes into B's master, and thus onto anyone cloning B's master when they pull.

What I conceptually want is this:

master      x_master
 [A] <---------> [B] <-------> [Dev2]
                  ^-------> [Dev1]
                  master

Eventually I'd need to push changes in B's master up to A's master when all the dev is done, but there will be changes going on in A that need to be merged into B

  • How do I set this up?
  • How do I push and pull from B into and from A?
  • Does this setup make sense?

I've tried all kinds of clone --mirror, branch --track, and just don't seem to get the changes in A and B pushing and pulling correctly.

解决方案

I am sure there is a shortcut for it, but I tend to just use basic commands. In any case, set up repository for B:

$ cd repo_B
$ git init --bare
$ git remote add upstream URL_FOR_REPO_A
$ git fetch upstream +master:refs/heads/x_master
$ git branch master x_master

When upstream repository is modified, you need to pull those changes in on the bare repository1:

$ git fetch upstream +master:refs/heads/x_master

This will overwrite2 any possible changes in x_master, so you'd better leave that branch alone. :)

You will want to merge upstream changes in x_master into master when/if A changes. Unfortunately, there may be conflicts at this stage, so it must be done with a clone of our bare repository. Simply clone the B repository (to a local or a remote location), and merge x_master into master, resolve the conflicts, and push back.

And the final task is pushing development done in master to repository A. This can be done in two ways. The first is by directly pushing B's master to repository A. This can be done by running:

$ git push upstream

on repository B. An alternative is a more controlled merge from master to x_master using a third repository:

$ git clone URL_FOR_REPO_A
$ cd repoDir
$ git remote add dev URL_FOR_REPO_B
$ git fetch dev
$ git branch --track master_b dev/master
$ git merge master_b
$ <resolve conflicts, if any>
$ git push origin master


Note 1

For completion, you can configure the remote to only fetch that branch by default:

$ git configure branch.upstream.fetch +master:refs/heads/x_master

And with --add, you can even add more branches to fetch:

$ git configure --add branch.upstream.fetch +branch_1_0:refs/heads/x_branch_1_0

Now, fetch will work properly without refspecs:

$ git fetch upstream


Note 2

To prevent pushes to master of repo_B, you can use a server-side hook like pre-receive or update.

这篇关于如何在git中设置临时存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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