当 git push 失败并显示“本地已过期”时,我该怎么办?

发布于 2024-10-03 22:22:44 字数 2038 浏览 0 评论 0原文

我确信这是一个非常简单的修复,但我不确定为什么我的 GitHub 推送失败。

现在它看起来像:

$ git push origin master
To [email protected]:user_name/project_name.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:user_name/project_name.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

并且:

$ git remote show origin
* remote origin
  Fetch URL: [email protected]:user_name/project_name.git
  Push  URL: [email protected]:user_name/project_name.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (local out of date)

另外,当我尝试 git pull 时:

$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "master"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

我做了什么导致这种状态......以及我应该做什么来修复它?

I'm sure this is a pretty easy fix, but I'm not sure why my pushes to GitHub are failing.

Right now it looks like:

$ git push origin master
To [email protected]:user_name/project_name.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:user_name/project_name.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

And:

$ git remote show origin
* remote origin
  Fetch URL: [email protected]:user_name/project_name.git
  Push  URL: [email protected]:user_name/project_name.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (local out of date)

Also, when I try a git pull:

$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "master"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

What did I do to cause this state ... and what should I do to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦行七里 2024-10-10 22:22:44

从远程拉取

git pull origin master

To pull from remote

git pull origin master
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文