无法将本地分支推送到远程Git回购

时间:2022-04-04 16:24:40

I have a problem with a git repo that is shared between multiple developers. A branch seems to have gone missing (kind of) and when I try to push to the remote repo with this branch I receive the following message...

我遇到了一个在多个开发人员之间共享的git repo的问题。一个分支似乎已经丢失(种类),当我尝试使用此分支推送到远程仓库时,我收到以下消息...

To git@hades:bbis.git
 * [new branch]      dompdf0.52 -> dompdf0.52
 ! [rejected]        live -> live (non-fast-forward)
error: failed to push some refs to 'git@hades:bbis.git'
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.

There are 3 branches on the repo:

回购中有3个分支:

  • dompdf0.52 is a temp branch where I upgraded the dompdf (this is okay)
  • dompdf0.52是一个临时分支,我升级了dompdf(这没关系)
  • master
  • live (this is the problematic branch)
  • 直播(这是有问题的分支)

I am the only developer who uses the live branch (used for deploying to the live server), and I did some work directly in this branch (not a good idea I know, but this was a mistake) and committed locally. I get this error when I try to push.

我是唯一一个使用实时分支(用于部署到实时服务器)的开发人员,我在这个分支中直接做了一些工作(我知道这不是一个好主意,但这是一个错误)并在本地提交。我试图推动时出现此错误。

Other developers have no visibility of the live branch or dompdf0.5.2 branch (I created both of these, but have pushed them to the remote repo - they even show up in the gitweb interface as HEADS). Even when developers do a git pull --all it still doesn't pull these branches down.

其他开发人员没有实时分支或dompdf0.5.2分支的可见性(我创建了这两个分支,但已将它们推送到远程仓库 - 它们甚至在gitweb界面中显示为HEADS)。即使开发人员做了一个git pull -all,它仍然没有把这些分支拉下来。

Another strange phenomenon is that when viewing the log on gitweb it only shows the master, but when looking at the shortlogs for live branch it shows live at the same point where the master is in the master shortlog.

另一个奇怪的现象是,当查看gitweb上的日志时,它只显示主服务器,但是当查看实时分支的短日志时,它会显示主服务器在主服务器短信中的同一点。

I'm just a little confused as to what is going on here, from what I can see the live branch is in the remote repo but not showing in the main repo log.

我只是对这里发生的事情感到有些困惑,从我可以看到实时分支在远程仓库中但未显示在主仓库日志中。

Has anyone got any ideas? Let me know if you need any images from gitk

有没有人有任何想法?如果您需要来自gitk的任何图片,请告诉我

EDIT: Just thought I'd mention, I've tried to work around the error message by doing a git fetch and a git pull but to no avail. The only thing I've not tried is a git push --force because I don't want to lose my history.

编辑:只是想我提到,我试图通过执行git fetch和git pull来解决错误消息,但无济于事。我唯一没试过的是git push --force因为我不想失去我的历史。

EDIT 2: After running the script that sehe provided I received the following:

编辑2:运行提供的脚本后,我收到以下内容:

fatal: ref ed2cacdacad22c75ca765cfc996304c8c7c8a654 is not a symbolic ref
fatal: ref 98c37bd8a9ef2fc16e882c17b4c04f417ae7b2b2 is not a symbolic ref

2 个解决方案

#1


1  

What you are experiencing is simply that you are not allowed to push because someone has updated the branch inbetween. You need to pull this branch before you can push your changes. The reason git pull --all doesn't work is probably because your local live branch is not setup to track origin/live

你所经历的只是因为有人在中间更新了分支而不允许你推动。在推送更改之前,您需要拉动此分支。 git pull --all不起作用的原因可能是因为你的本地实时分支没有设置为跟踪origin / live

Try this:

尝试这个:

git branch --set-upstream live origin/live
git checkout live
git pull
git push

#2


1  

Perhaps 'live' is a symbolic reference to master? In that case, it acts merely as an alias, and updating it would (potentially?) update the master reference.

也许'直播'是高手的象征性参考?在这种情况下,它仅作为别名,更新它(可能?)更新主引用。

Symbolic refs should be updated with git-update-ref. To be honest, I have only once used a symbolic reference and never pushed them to a remote. It is possible that git push (send-pack or receive-pack) doesn't understand symbolic refs and tries to treat them as a normal ref by first resolving the symbolic reference.

应使用git-update-ref更新符号引用。说实话,我只使用了一个符号引用,从未将它们推到遥控器上。 git push(send-pack或receive-pack)可能无法理解符号引用,并尝试通过首先解析符号引用将它们视为普通引用。

See What's the recommended usage of a Git symbolic reference? for background

请参阅Git符号引用的推荐用法是什么?为背景

Backgrounder of git refs: http://progit.org/book/ch9-3.html

git refs的背景资料:http://progit.org/book/ch9-3.html

Use this to find out whether your branches are symbolic refs:

使用它来确定您的分支是否是符号引用:

for ref in $(git rev-list --branches --no-walk); do
    git symbolic-ref "$ref"
    git check-ref-format --print "$ref"
done

For all (remote) branches, add --all to rev-list

对于所有(远程)分支,将--all添加到rev-​​list

#1


1  

What you are experiencing is simply that you are not allowed to push because someone has updated the branch inbetween. You need to pull this branch before you can push your changes. The reason git pull --all doesn't work is probably because your local live branch is not setup to track origin/live

你所经历的只是因为有人在中间更新了分支而不允许你推动。在推送更改之前,您需要拉动此分支。 git pull --all不起作用的原因可能是因为你的本地实时分支没有设置为跟踪origin / live

Try this:

尝试这个:

git branch --set-upstream live origin/live
git checkout live
git pull
git push

#2


1  

Perhaps 'live' is a symbolic reference to master? In that case, it acts merely as an alias, and updating it would (potentially?) update the master reference.

也许'直播'是高手的象征性参考?在这种情况下,它仅作为别名,更新它(可能?)更新主引用。

Symbolic refs should be updated with git-update-ref. To be honest, I have only once used a symbolic reference and never pushed them to a remote. It is possible that git push (send-pack or receive-pack) doesn't understand symbolic refs and tries to treat them as a normal ref by first resolving the symbolic reference.

应使用git-update-ref更新符号引用。说实话,我只使用了一个符号引用,从未将它们推到遥控器上。 git push(send-pack或receive-pack)可能无法理解符号引用,并尝试通过首先解析符号引用将它们视为普通引用。

See What's the recommended usage of a Git symbolic reference? for background

请参阅Git符号引用的推荐用法是什么?为背景

Backgrounder of git refs: http://progit.org/book/ch9-3.html

git refs的背景资料:http://progit.org/book/ch9-3.html

Use this to find out whether your branches are symbolic refs:

使用它来确定您的分支是否是符号引用:

for ref in $(git rev-list --branches --no-walk); do
    git symbolic-ref "$ref"
    git check-ref-format --print "$ref"
done

For all (remote) branches, add --all to rev-list

对于所有(远程)分支,将--all添加到rev-​​list