将现有的Git存储库推送到Github只发送大约一半的提交? [英] Pushing an existing Git repository to Github only sends about half the commits?

查看:85
本文介绍了将现有的Git存储库推送到Github只发送大约一半的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地的Git仓库,我一直在开发几天:它迄今为止有18次提交。今晚,我创建了一个私人的Github存储库,我希望它能够推动它;然而,当我这样做的时候,它最终只把十八个提交中的八个提交给Github。我删除了Github repo并重试,结果相同。



有关为什么会发生这种情况的任何想法?我已经完成了这个程序,但没有成功几次,所以我有点难住。



更新:有,并已一直以来,只有这个回购中的主分支。只是为了解决一些已发布的答案......

解决方案

我看了一下有关存储库的问题,这里是什么继续:




  • 在某些时候,rpj执行了 git checkout [commit id] 。这指出HEAD在一个松散的提交而不是一个公认的分支。我相信这是CesarB提到的悬崖之巅问题。
  • 没有意识到这个问题,他继续做出改变并提交它们,每次都会碰到HEAD。然而,HEAD只是指着一个悬而未决的提交链,而不是一个公认的分支。
  • 当他推动他的更改时,git将所有内容推到了master的顶部,这是只有当前树的一半左右。

  • 造成混淆



  • 此图应该让它更清楚:

       -  D  -  E  -  F 
    / ^
    A - - B - C - |
    ^ ^ HEAD
    | |
    远程主

    当他试图推动他的更改时,只有一个 C 被推送,远程上移到 C 。他无法获取提交 D F 来推送,因为它们未被已知分支引用。 p>

    以下是您在此状态下看到的内容:

      $ git branch 
    *(no branch)
    master

    解决方案是移动 master 在悬挂提交链中最多为 F




    • 为当前状态创建合法分支:



      git checkout -b tmp




      • tmp 分支现在指向上图中的提交 F


    • 快进 master tmp



      git checkout master



      git merge tmp $ b $ ul
      $ c $ master $现在指向commit ˚F



  • 丢掉您的临时分支

    git branch -d tmp


  • 您可以愉快地推送到远程存储库,并发送所有更改。 / p>



I have a local Git repository I've been developing under for a few days: it has eighteen commits so far. Tonight, I created a private Github repository I was hoping to push it to; however, when I did so, it only ended up pushing eight of the eighteen commits to Github. I deleted the Github repo and retried, with the same result.

Any thoughts on why this might be happening? I've done this procedure before without a few times successfully, so I'm a bit stumped.

Update: There is, and has always been, only the master branch in this repo. Just to address a few of the posted answers...

解决方案

I took a look at the repository in question and here's what was going on:

  • At some point, rpj had performed git checkout [commit id]. This pointed HEAD at a loose commit rather than a recognized branch. I believe this is the "dangling HEAD" problem that CesarB is referring to.
  • Not realizing this problem, he went on making changing and committing them, which bumped HEAD up every time. However, HEAD was just pointing at a dangling chain of commits, not at a recognized branch.
  • When he went to push his changes, git pushed everything up to the top of master, which was only about halfway through the current tree he was on.
  • Confusion ensued

This diagram should make it more clear:

                 -- D -- E -- F
                /             ^
   A -- B -- C -              |
   ^         ^               HEAD
   |         |
 remote    master

When he tried to push his changes, only A through C were pushed and remote moved up to C. He couldn't get commits D through F to push because they aren't referenced by a known branch.

Here's what you see when you're in this state:

$ git branch
* (no branch)
master

The solution is to move master up to F in the dangling chain of commits. Here's how I did it.

  • Create a legitimate branch for the current state:

    git checkout -b tmp

    • The tmp branch is now pointing at commit F in the diagram above
  • Fast-forward master to tmp

    git checkout master

    git merge tmp

    • master is now pointing at commit F.
  • Throw away your temporary branch

    git branch -d tmp

  • You can happily push to the remote repository and it should send all of your changes.

这篇关于将现有的Git存储库推送到Github只发送大约一半的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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