为什么我会收到“错误:无法推送一些参考文献”? [英] Why do i get "error: failed to push some refs"?

查看:217
本文介绍了为什么我会收到“错误:无法推送一些参考文献”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程git存储库和本地的一个工作。每当我在本地做任何更改时,我都会将它们推到遥控器上。然后,我有时会在远程文件上执行git commit,以将更改存储在远程文件中。

I have a remote git repository and a local one that i work with. Whenever i do any changes locally, i push them to the remote. Then i sometime do a "git commit" on the remote one to store the changes on the remote files.

我根本不直接编辑远程存储库。我只是承诺修改。我是一名开发人员,没有其他人在该回购站工作。

I do not edit the remote repository directly at all. I just commit the changes. And i'm a single developer, no one else works on that repos.

为什么我得到一个错误,据我所知,这意味着我必须拉首先?

Why do i get an error that, from what i know, means that i have to pull first ?

我不想拉,因为远程回购文件已过时,并且会丢失本地更改。这真的很烦人,为什么会这样呢?我怎样才能解决而不必拉或重新创建存储库? (如你所见,这就像是一个颠覆式的版本控制风格)

I don't want to pull because the remote repos files are outdated and it will lose my local changes. This is really annoying, why does this happen ? And how can i fix without having to pull or recreate the repository ? (as you can see, this is sort of like a subversion type of version control style here)

编辑 - 错误:

EDIT - The error :

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


推荐答案

一个裸仓库。裸仓库就是git仓库,没有当前的结账(就是说,它就像常规Git仓库中 .git dir的内容一样,所以它包含对象和引用,但它没有文件层次结构的索引或工作副本)。如果您尝试推送到非裸仓库,工作副本将与提交的内容不同步,并导致您在此处看到的各种问题。

What you should be doing is creating the remote repository as a bare repository. A bare repository is just the git repo, without a current checkout (that is, it is like just the contents of the .git dir in a regular Git repo, so it contains objects and refs, but it doesn't have an index or working copy of the file hierarchy). If you try pushing to a non-bare repository, the working copy will get out of sync with what is committed, and cause the kinds of problems you are seeing here.

您可以使用 git init --bare repo.git 创建一个裸存储库。或者,您可以使用 git clone --bare original-repo new-repo.git 来将现有存储库克隆为裸回购。

You can create a bare repository using git init --bare repo.git. Or you can clone an existing repository as a bare repo using git clone --bare original-repo new-repo.git.

如果您想要在服务器上检出存储库的副本,则需要在服务器上创建一个新的非正式存储库,然后从您推送的裸回购库中取回该存储库。 。

If you want to have a checked out copy of the repository on your server, you will need to create a new, non-bare repo on the server, and then pull into that repo from the bare repo that you push to.

这篇关于为什么我会收到“错误:无法推送一些参考文献”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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