git:您的分支和“origin/somebranch”已经分叉 - 如何放弃本地提交

27

我有一个问题,其中最接近我的问题已经被提出,但无法添加评论。

git:您的分支和'origin/master'已经分歧-如何放弃本地提交?

我运行了上面问题的提示和答案,但没有解决。我正在使用软件源树跟进进度图表。我关闭软件并在bash git中运行命令。但是同样的错误被引用。

# Your branch and 'origin/master' have diverged,
# and have 7 and 11 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)

我也遇到了同样的问题。按照运行2个comentos的步骤,但没有起作用。我认为我的问题是,在我为单独的头部检出并做了提交之前,我回到了树分支/主分支,然后提交了我所做的提交,我相信这引用了个别树头。总之,我无法撤消此提交,我在SourceTree软件上以图形方式显示。

编辑-添加信息: 我想扔掉未发布的提交并进行服务器检出。但我在互联网上找到的解决方法都不起作用。我还尝试在gitBash中使用git reverse,但控制台显示我要做deveo的消息。

$ Git status
On branch processos_criminais_151029
Your branch and 'origin / processos_criminais_151029' have diverged,
and 7 and 11 have different commits each, respectivamente.
   (use "git pull" to merge the remote branch into yours)

Changes not staged for commit:
   (use "git add <file> ..." to update what will be committed)
   (use "git checkout - <file> ..." to discard changes in working directory)

我尝试了这两个解决方案,但都没有起作用。如果我试图推送会出现大量文件冲突的问题,我尝试使用自动合并来解决这些问题,但是当我运行新的git status时,它指出同样数量的文件存在冲突。


1
“但是没有起作用” - 它们为什么没有起作用?在运行 git reset --hard origin/master 后,git status 的输出是否保持不变? - poke
你究竟想要做什么?你期望存储库的最终状态是什么? - ffledgling
我想丢弃未发布的提交并进行服务器检出。但是我在互联网上找到的解决方案不起作用。 - Paulo Victor
2个回答

87

您的分支和 'origin/processos_criminais_151029' 已经发生了分歧

所以,重置为 origin/master 当然行不通。您需要重置为远程分支才能将本地分支重置为它。

因此,您需要运行以下命令:

git fetch origin
git reset --hard origin/processos_criminais_151029

是的,这就是有效的方法。 - iCyborg

-5

我用这个链接解决了这个问题:https://dev59.com/MFwY5IYBdhLWcg3wcHXZ#32630762

但是完成答案需要以下步骤:

然后我进行了:

git pull

将更改添加到文件中并执行:

git push

一切都完美运作

敬礼


这将创建一个合并提交。 - Bernhard Döbler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接