Git推送到refs / remotes / mine / master [英] Git push to refs/remotes/mine/master

查看:176
本文介绍了Git推送到refs / remotes / mine / master的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在跟踪远程存储库,即我有 refs / remotes / joe / master



我知道想尽快将joe的更改加入我的仓库。

我不想使用 fetch ,因为我可能不在电脑在他提交时。所以我告诉他:我可能会出去购物,所以请把你的改变推到 refs / remotes / joe / master

原因I我希望他的回复能够尽快完成,因为他在晚上关掉了电脑,所以当我从购物中回来时,我无法获取他的更改。



我知道joe应该设置一个裸露的公共存储库,但这是一个开销。



推荐给 refs / remotes / joes / master 在这种情况下可以做的事情?

解决方案

保持多个(非裸)Git仓库同步的最好/最简单的方法提出用更新后的钩子来处理这种贡献。不过,有一个更直接的解决方案: OP zedoo 评论,(由Git的维护人Junio C Hamano在2007年写的)详细信息:

(这是一个很棒的例子) 适用于非裸回购的情况




receive-pack没有更新 HEAD reflog,因为它更新了实际的分支,而不是 HEAD

如果您推送到 HEAD ,您应该看到 HEAD

当您推入底层时,如何拆分 HEAD 分支,并使 HEAD 一个非symref?


我不认为需要任何复杂的东西,我认为有人提到了一个很好的例子,它是一个防火墙主机,只能被推入。

在这个例子中,尽管他知道自己可以在理想世界中反向获取,但网络配置并不允许他这样做,因此需要按。

为了处理这种情况,在非裸仓库之间进行推送的人可能会忘记推入分支机构。它们可以将它们的推送作为他们希望能够执行的真正的镜像镜像 。 b
举例说明:



回购 A 只能推入,如果您<您可以:




<$ em $>可以从回购中获取 B










$ b $同像这样:




  [remoteB] fetch = refs / heads / *: refs / remotes / B / * 




但不幸的是,从 B A 中,您可以在 B 相反:



  $ git push A 




与:



  [remoteA] push = refs / heads / *:refs / remotes / B / * 




在您执行推送操作后,您通过repo A 来到机器上,并且记住你所做的是 git fetch B 的镜像,你可以:



  $ git merge remotes / B / master 




完成了。

换句话说,不要想起参考文献/远程s / B 作为使用 git fetch 的一部分。

它的目的是跟踪远程仓库 B 的元首


您可以通过在仓库中发布提取来维护该层次结构 A

您也可以在存储库 B 中执行push操作。



<几乎每一天我都会进入一个实时存储库。

我典型的一天总结如下:



  gitster $ git push kernel-org-private 
gitster $ ssh kernel.org
kernel.org $ git merge origin
kernel.org $ Meta / Doit - 迂腐&
kernel.org $ exit
...去喝我的茶......



< blockquote>

其中


  1. gitster 是我的私人开发机器

  2. kernel.org 是友好的k.org伙伴向我提供的机器

  3. Meta 是我的' todo '分支和

  4. Doit 是构建所有四个公共分支的脚本。 ' master '在我的 kernel.org 存储库中签出,并且从我的私有机器推送完成仍然使用非分离的远程布局):



     推送:refs / heads / master: refs / heads / origin 
    Push:refs / heads / next:refs / heads / next
    Push:+ refs / heads / pu:refs / heads / pu
    Push:refs / heads / maint:refs / heads / maint




    我做了登录到 kernel.org 机器将运行 git merge origin 以将< master '最新。

    如果您认为' push '是镜像' code> fetch
    '你会理解为什么。

    这就像在 kernel.org上发出git fetch code> machine从我的私有机器中检索hot-off-press,然后 git merge 它(通常是 git拉会做为
    单步执行)。



    然而,有时我不小心将'下一步'检出。

    如果我发现我已经检出了非' master ',我会做 git reset --hard HEAD 在做任何事情之前,我不希望我的推送有时会导致分离 HEAD 有时不会。

    我不想失去最后一个分支的信息(因为接下来我要做的就是找出哪个分支 / Doit 失败)。
    如果我有时被错误地插入到活动分支中足够让人恼火,我会切换到单独的远程布局并推入到 remotes / origin / * 层次结构中,并且会有
    真正没有什么可担心的。



    I am tracking a remote repository, i.e. I have refs/remotes/joe/master.

    I know would like to get joe's changes as soon as possible into my repository.
    I don't want to use fetch, because I might not be at the computer when he commits. So I tell him: I might be out for shopping, so please just push your changes to refs/remotes/joe/master.
    The reason I want his changes asap in my repo is that he turns off his computer in the evening, so I wouldn't be able to fetch his changes when I come back from shopping.

    I know that joe should just setup a bare, public repository, but this is sort of an overhead.

    Is pushing to refs/remotes/joes/master an okay thing to do in such a case?

    解决方案

    "best/simplest way to keep multiple (non-bare) Git repos in sync" proposes to deal with that kind of contribution with a post-update hook.

    However, there is a more straightforward solution:

    As The OP zedoo comments, the thread on git push to a non-bare repo (written by Git maintainer Junio C Hamano, back in 2007) details:
    (and it is a great example of a case where it is appropriate to push to a non-bare repo)

    receive-pack isn't updating the HEAD reflog as its updating the actual branch, not HEAD.
    If you pushed instead to HEAD you should see the HEAD reflog entry too.

    What about splitting HEAD when you push to the underlying branch, and making HEAD a non-symref?

    I do not think any of the complication is needed, and I think somebody mentioned a good example, which is a firewalled host that can only be pushed into.
    In that example, even though he knows he could fetch in reverse direction in the ideal world, the network configuration does not let him do so, hence need for a push.

    To deal with that sanely, people who push between non bare repositories can just forget about pushing into branch heads.

    Instead, they can arrange their pushes to be a true mirror image of their fetch that they wish could do.
    To illustrate:

    On repo A that can only be pushed into, if you could fetch from repo B, you would:

    $ git fetch B
    

    with something like this:

    [remote "B"] fetch = refs/heads/*:refs/remotes/B/*
    

    But unfortunately because you can only push into A from B, you would run this on B instead:

    $ git push A
    

    with:

    [remote "A"] push = refs/heads/*:refs/remotes/B/*
    

    And after you perform your push, you come to the machine with repo A on it, and remembering that what you did was a mirror image of "git fetch B", you would:

    $ git merge remotes/B/master
    

    and you are done.

    In other words, don't think of refs/remotes/B as something that is for the use of "git fetch".
    Its purpose is to track the remote repository B's heads
    .
    You maintain that hierarchy by issuing fetch in repository A.
    You can issue push in repository B to do so as well.

    I push into a live repository almost every day.
    My typical day concludes like this:

    gitster$ git push kernel-org-private
    gitster$ ssh kernel.org
    kernel.org$ git merge origin
    kernel.org$ Meta/Doit -pedantic &
    kernel.org$ exit
    ... go drink my tea ...
    

    where

    1. gitster is my private development machine
    2. kernel.org is a machine made available to me by friendly k.org folks
    3. Meta is a checkout of my 'todo' branch and
    4. Doit is a script to build all four public branches.

    I always leave 'master' checked out on my kernel.org repository, and the push from my private machine is done with (I still use the non separate-remote layout):

    Push: refs/heads/master:refs/heads/origin
    Push: refs/heads/next:refs/heads/next
    Push: +refs/heads/pu:refs/heads/pu
    Push: refs/heads/maint:refs/heads/maint
    

    So the first thing I do after logging in to kernel.org machine is to run "git merge origin" to bring the 'master' up-to-date.
    If you think of 'push' being mirror image of 'fetch' you would understand why.

    It is like issuing "git fetch" on kernel.org machine to retrieve the hot-off-the-press from my private machine and then "git merge" it (usually "git pull" would do that as a single step).

    However, sometimes I accidentally leave 'next' checked out.
    If I find out that I left non 'master' checked out, I would do "git reset --hard HEAD" before doing anything else, and I do not want my push to sometimes result in detached HEAD and sometimes not.
    I do not want to lose the information which branch I was on last (because the next thing I would do is to find out on which branch Meta/Doit failed).
    If I were annoyed enough by sometimes mistakenly pushing into the live branch, I would switch to separate remote layout and push into remotes/origin/* hierarchy, and there will be truly nothing to worry about after that point.

    这篇关于Git推送到refs / remotes / mine / master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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