无法合并两台计算机的更改

发布于 2025-01-24 11:12:32 字数 1407 浏览 1 评论 0原文

我的解决方案存储在GitHub上,我正在使用Visual Studio的内置功能来检查内外的代码。目前,我是唯一从事我项目的人。但是我已经开始在不同的计算机之间切换。

每当我到达两台计算机都进行待处理的地方时,我都无法继续。

我正在尝试在一台计算机上推动我的更改,这给了我一个错误:

由于您的本地分支在远程分支后面,因此无法推动远程存储库。在推动之前拉动分支。

[拉然后推] [拉] [取消]

如果我选择[pull then stuph],我会遇到不同的错误。

拉力操作失败。有关详细信息,请参见输出窗口。

输出窗口显示以下内容。

Pushing master
Hint: You have divergent branches and need to specify how to reconcile them.
Hint: You can do so by running one of the following commands sometime before
Hint: your next pull:
Hint: 
Hint:   git config pull.rebase false  # merge
Hint:   git config pull.rebase true   # rebase
Hint:   git config pull.ff only       # fast-forward only
Hint: 
Hint: You can replace "git config" with "git config --global" to set a default
Hint: preference for all repositories. You can also pass --rebase, --no-rebase,
Hint: or --ff-only on the command line to override the configured default per
Hint: invocation.
Git failed with a fatal error.
Git failed with a fatal error.
Need to specify how to reconcile divergent branches.

两个系统都显示当前分支为 master 。我期望将更改合并,所以我不确定为什么这是一个问题。

有什么方法可以让视觉工作室合并更改并让我处理任何冲突?

注意:我正在尝试阅读此信息,但我没有为此使用命令行。我很想只使用IDE。似乎应该支持我要做的事情。我所读的内容似乎表明我需要在拉动设置时设置 rebase本地分支,但是我不确定我应该设置什么或为什么。

My solution is stored on GitHub and I'm using the built-in features of Visual Studio to check code in and out. Currently, I'm the only one working on my project. But I've started switching between different computers.

Every time I get to where both computers have pending changes, I am unable to continue.

I'm trying to push my changes on one computer and it gives me an error:

Unable to push the remote repository because your local branch is behind the remote branch. Update your branch by pulling before pushing.

[Pull then Push] [Pull] [Cancel]

If I select [Pull then Push], I get a different error.

The pull operation failed. See the Output window for details.

And the Output window shows the following.

Pushing master
Hint: You have divergent branches and need to specify how to reconcile them.
Hint: You can do so by running one of the following commands sometime before
Hint: your next pull:
Hint: 
Hint:   git config pull.rebase false  # merge
Hint:   git config pull.rebase true   # rebase
Hint:   git config pull.ff only       # fast-forward only
Hint: 
Hint: You can replace "git config" with "git config --global" to set a default
Hint: preference for all repositories. You can also pass --rebase, --no-rebase,
Hint: or --ff-only on the command line to override the configured default per
Hint: invocation.
Git failed with a fatal error.
Git failed with a fatal error.
Need to specify how to reconcile divergent branches.

Both systems show the current branch is master. I was expecting the changes to be merged so I'm not sure why this is a problem.

Is there any way to get Visual Studio to merge the changes and allow me to deal with any conflicts?

Note: I'm trying to read up on this but I am not using a command line for this. I would far prefer to just use the IDE. And it seems like it should support what I'm trying to do. What I've read seems to indicate I need to set the Rebase local branch when pulling setting, but I'm not sure what I should set it to or why.

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

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

发布评论

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

评论(1

薄暮涼年 2025-01-31 11:12:32

如果您在Visual Studio 2019或更高版本上,则应该能够关注这些说明以设置项目项目的git pull策略。

此答案
对您从Git看到的警告进行了详尽的解释。基本上,git希望您设置一种配置,以告诉它如何处理您试图更新与本地分支有所不同的远程分支的情况。将其设置为false将为您提供您可能使用的行为,但我更喜欢true个人。

在Visual Studio中设置配置(或Git建议的命令行中)将解决错误。至于您应该选择哪种选项进行配置,这确实取决于您。但是,我将简要概述每个选项:

  • “正确:在提取后将电流分支重新列在上游分支的顶部。”
    • 经验丰富的GIT用户首选的更高级选项。它将重写本地分支的历史记录,就像在上游分支上进行了任何更改之后进行这些更改一样。如果您关心的话,这将为您提供更清洁的git历史记录。不利的一面是,如果您想在当地进行许多小型委托,则可能会遇到需要解决每个人提交的合并冲突而不是一次解决所有冲突的情况。
  • “错误:将当前分支合并到上游分支。”
    • “默认”选项。这就是您和大多数开发人员期望发生的事情。它首先在您本地的分支上创建一个合并官方,使您可以立即解决任何冲突,无论您当地有多少尚未在上游分支上的投入,然后推动。
  • “ Unsot(默认):除非在其他配置文件中指定,否则将当前分支合并到上游分支中。”
    • 文档在此处已过时:GIT的较新版本要求您拥有此配置集。因此,除非您将其明确将其设置为false
    • ,这将不会自动使用默认行为。

  • “交互式:在交互模式下重新构想。”
    • true的高级版本。在您倾向于在本地进行大量小型投入的情况
  • “保存:反弹而不会使本地创建的合并提交不扁平。”


If you're on Visual Studio 2019 or above, you should be able to follow these instructions to set the git pull strategy for your project.

This answer
gives a thorough explanation of the warning that you're seeing from Git. Basically, git wants you to set a configuration to tell it how to handle situations where you're attempting to update a remote branch that has diverged from your local branch. Setting it to False will give you the behavior that you're probably used to, but I prefer True personally.

Setting the configuration in Visual Studio (or at the command line, as suggested by git), will resolve the error. As for which option you should choose for the configuration, that's really up to you. But I'll give a brief overview of each option:

  • "True: Rebase current branch on top of upstream branch after fetch."
    • Slightly more advanced option that's preferred by more experienced Git users. It will rewrite the history of your local branch to appear as if you made these changes after any changes on the upstream branch. This will give you a cleaner git history, if you care about that. The downside is that if you like to make many small commits locally, you may run into situations where you need to resolve merge conflicts on each individual commit rather than resolving all of your conflicts once.
  • "False: Merge the current branch into the upstream branch."
    • The "default" option. It's what you and most devs expect to happen. It first creates a merge-commit on your branch locally, allows you to resolve any conflicts at once, regardless of how many commits you have locally that are not yet on the upstream branch, and then it pushes.
  • "Unset (default): Unless specified in other configuration files, merge the current branch into the upstream branch."
    • The docs are outdated here: newer versions of git require that you have this config set. So this will not automatically use the default behavior unless you explicitly set it to False.
  • "Interactive: Rebase in interactive mode."
    • Slightly more advanced version of True. Useful in the case where you tend to make a lot of small commits locally, since it will give you an opportunity to rewrite your local commit history.
  • "Preserve: Rebase without flattening locally created merge commits."
    • Equivalent to rebasing with the merges option. You're unlikely to need this unless you commonly perform local merges.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文