【问题标题】:How to update local repo with master?如何使用 master 更新本地仓库?
【发布时间】:2015-01-15 01:58:48
【问题描述】:

我习惯使用 SVN,最近才切换到 GitHub。

我正在尝试更新 GitHub 存储库中的一些文件,但收到以下消息:

To https://github.com/.../
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/.../'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我已经尝试过像git fetch origingit pull 这样的命令,但是这些都没有成功,所以我当前的分支并不落后。

在 SVN 中,我只需执行 svn update,然后提交我的更改。

我也试过git pull origin,但我收到一条奇怪的短信,我不知道如何与之交互:Updating a local repository with changes from a Github repository

【问题讨论】:

  • 通常git pull 将合并来自远程的提交,这样您的分支就不会落后并允许您推送。 git remote -vgit branch -vv 的输出是什么?
  • 我通过克隆和复制我的更改手动修复它。我之前尝试过git pull,但它要求澄清我从中提取的分支名称。如果我这样做git pull origin,则会打开一个类似 EMAC 的文件,要求解释我为什么要合并。

标签: git svn github


【解决方案1】:
  1. 使用以下命令检查您当前的分支:

    git 分支

    它将显示您当前的分支名称,名称旁边带有星号 (*)。

  2. 然后用远程分支更新你的本地分支:

    git pull origin branchname(这是带星号的分支名称)

  3. 如果您已经使用以下命令提交了本地更改,现在您可以将代码推送到远程存储库:

    git push origin 分支名

如果您还没有提交,请先执行 commit,然后执行 git pullpush

【讨论】:

    【解决方案2】:

    拉取时git打开编辑器是正常的。这是因为您正在将更改从远程合并到本地分支。

    当你拉取时,git 会检测它是否需要将你的本地分支与远程分支合并。如果它需要合并,它会这样做并为您提供为合并提交编写自定义消息的机会。此时,您可以选择只关闭编辑器,git 将完成该过程。

    基本上,您只需关闭编辑器就可以了。

    本质上,git 正在做以下事情:

    #Download all the commits from the remote
    git fetch origin
    
    # Merge in the commits from the remote to your local branch
    # If anything needs merging, this will open a text editor
    git merge origin/master master
    

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 2018-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多