git push如何至两个git仓库
PHP中文网
PHP中文网 2017-04-27 09:02:42
0
7
762

分别有仓库 A(github),B(JAE 的 git),本机为C。

A, B都进行了 README.md 的初始化,就是说,这个情况下,已经存在冲突了,log不一致。

先从仓库A获取下来,C 修改完毕提交,顺利提交至A,

此时 如何从 C 提交到B,需要进行多少操作,使得仓库记录 A 和 B 的log一致(后面一致即可)?

这个问题我尝试过,没解决。

PHP中文网
PHP中文网

认证高级PHP讲师

reply all (7)
某草草

After so long, after continuous use of git, I also know the specific method.

Assume that warehouse a is the final use warehouse and b is the release warehouse. The branches are all dev

Now I will reply to myself:

The first step is to add a remote warehouse
git remote add origin1 git.a
git remote add origin2 git.b

The second step is to ensure that there is nothing changed locally, pull the remote warehouse address, and then rebase.
git fetch origin1
git rebase -i origin1/dev

If there is a conflict, resolve it.

git push -f origin1 dev
git push -f origin2 dev

done.

    漂亮男人

    In fact, you can clear the initialization files and add the address of another remote warehouse to the local .git/config, such as:
    [remote "all"]
    url = https://github.com/segment/test.git
    url = https://git.oschina.net/segment/test.git
    The subsequent operations are the same. Submitting the code will be submitted to the two warehouses simultaneously.

      阿神

      I haven’t tried the situation of two git repositories. My guess is this:

      1.git remote add $C remote warehouse name $C remote warehouse url

      2.fetch to C

      3. Local merge

      4.push $C remote warehouse name $project name

      Reference: http://www.git-scm.com/book/zh/Git-%E5%9F%BA%E7%A1%80-%E8%BF%9C%E7%A8%8B%E4%BB %93%E5%BA%93%E7%9A%84%E4%BD%BF%E7%94%A8

        漂亮男人

        The solution to keep all logs of a branch (assumed to be the master branch) the same:

        1. Add B to the remote list git remote add jae git://xxxxx@xxxx.git
        2. Assume that C has synchronized A and completed the modification. Then you need to submit C to B. At this time, you need to force the submission to avoid the problem of conflict being unable to submit: git push jae master:master --force

        After pushing it up, the logs of C and B will be consistent, and you can continue the operation after that

        If you want to keep all branches consistent, I suggest you simply create a new project on jae and push C up

        Hope it helps you

          伊谢尔伦

          I guess, before pulling from any remote repository, first

          git stash

          Then pull, modify, add, submit, push. Again

          git stash pop

          Then resolve conflicts if there are any. If there are no conflicts, directly pull the code from another remote warehouse, and then modify, add, submit, and push step by step.
          It's all based on guessing. Please practice it yourself if you are specific. for reference only.

            Peter_Zhu

            I think you already know how to add multiple remote repositories, so I won’t go into that.

            Straightforward: When C=A, under Cgit push -f 'B远程仓库' '分支'In this way, although B will conflict with A C, it will be forced to overwrite the state of C. So A=B=C. The LOG will be consistent after that. The -f parameter means forced push.
            just try it

              我想大声告诉你

              Just configure the mirror warehouse
              1.git remote add --mirror=push --mirror=fetch repoName url
              2.git push repoName master

                Latest Downloads
                More>
                Web Effects
                Website Source Code
                Website Materials
                Front End Template
                About us Disclaimer Sitemap
                php.cn:Public welfare online PHP training,Help PHP learners grow quickly!