推送更改到Git存储库导致”更新被拒绝”错误,如何修复?

huangapple go评论110阅读模式
英文:

Pushing changes to Git repository results in 'Updates were rejected' error, how to fix it?

问题

抱歉,以下是翻译好的部分:

我在一个在线代码库上,只有我能够推送提交,除了主分支外没有其他分支。最近这些天,我一直在上面工作,并成功推送了提交,包括文件夹和文件等。

但是今天,当我尝试推送更改以更新代码库中的最新文件和文件夹时,出现了以下错误:

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

我正在使用Pycharm社区版13.2,通常通过在左侧菜单中选择“提交”部分,然后编写注释并推送提交来更新代码库,就像这里的操作一样:推送更改到Git存储库导致”更新被拒绝”错误,如何修复?

我也从未在在线代码库上进行过任何更改,始终保持本地文件,然后进行推送。我已经尝试过获取和更新项目,但没有解决问题,所以在破坏我的代码库之前,我想寻求帮助。

编辑:我确实对在线代码库进行了一些更改。我添加了一个LICENSE.md文件,它显示在我的远程历史更改中。推送更改到Git存储库导致”更新被拒绝”错误,如何修复?

英文:

I have an online repository on which I am the only person that can push commits, and there are no more branches than the main one. I have been working on it these days, and pushed commits without an issue, including folders and files etc.

Except today, when I try to push changes to update the repository with the latest files and folders I have, it gives me this error:

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

I am using Pycharm Community Edition 13.2, and always update by selecting the Commit section in the left bar menu and then writing a comment and pushing the commit like in here: 推送更改到Git存储库导致”更新被拒绝”错误,如何修复?

I also never touched the online repository to make any changes, always kept local files which were then pushed. I already tried to fetch and to update the project but it didn't fix, so before I break my repository I want to ask for help

EDIT: I did make some changes to the online repository. I had added a LICENSE.md file which shows up in my remote history changes. 推送更改到Git存储库导致”更新被拒绝”错误,如何修复?

答案1

得分: 1

你说你是唯一一个推送该存储库的人,但Github告诉你你的版本落后于远程版本。

首先,我建议您检查远程历史记录,以查看是否有其他人推送了其他内容。

如果您发现有一些远程更改,您应该使用git pull -r执行带有rebase的git pull。

英文:

You say that you are the only one who push on that repository, but Github tells you that your head is older (behind) the remote one.

Before of all, I suggest you to inspect the remote history to check if somebody (?) pushed something else.

If you will discover some remote changes you should do a git pull with a rebase by git pull -r.

huangapple
  • 本文由 发表于 2023年6月1日 14:45:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定