如何推送一个新分支?

3
我创建了一个新分支。
在进行一些修改后,我想将该分支推送到服务器。
git commit  -m 'New branch'

13 files changed, 694 insertions(+), 36 deletions(-)

git push origin malix1.0
Everything up-to-date

为什么一切都是最新的?
 git branch
* (no branch)
  malix1.0

我在哪里犯了错?
1个回答

3
我认为在您创建了新分支“malix1.0”之后,您以某种方式将存储库放入了所谓的"detached HEAD"状态,因此您的新提交未记录在该分支上。
然后,当您运行git push origin malix1.0时,Git会获取“malix1.0”分支的内容,并尝试更新远程存储库中同名的分支。由于该分支与远程存储库中的匹配分支相比没有任何新内容,因此不会发生任何事情。
要摆脱这种情况,请执行以下操作:
  1. Make a branch out of your current state:

    git branch temp
    

    Otherwise you will need to rely on the git reflog functionality to get hold on your work after you check out a branch.

  2. Update your "mailx1.0" branch with your work:

    git checkout mailx1.0
    git merge temp
    

    That is, you check out the branch which was intended to receive your new commits and then merge in the temporary branch which is actually holding those commits.

  3. Delete that temporary branch:

    git branch -d temp
    

    This branch is no longer needed as the work it contained compared to "mailx1.0" is now on that "mailx1.0" branch as well.

  4. Push out your updated branch:

    git push origin mailx1.0
    

一般而言,参见此处此处 - kostix
我不得不修改第二步:git checkout -b mailx1.0 origin/malix1.0。但其他一切都完美地运作了。谢谢。 - Kicsi Mano
@KicsiMano,我想知道为什么你必须从origin/malix1.0创建 malix1.0,因为你引用的git branch输出明确包含了那个分支malix1.0。;-) 不管怎样,很好它对你起作用了! - kostix

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接