git 发生冲突时,Windows 版 GitHub 使我处于“变基”状态,如何从那里开始?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15149953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:15:07  来源:igfitidea点击:

On conflict, GitHub for Windows puts me in "rebasing" state, how to go from there?

gitgit-rebasegithub-for-windows

提问by Nicolas Raoul

I recently started using GitHub for Windows.

我最近开始使用GitHub for Windows

I just got a conflict. On command line I would know how to handle this, but GitHub for Windows choosed to put me in a state I am not familiar with:

我刚刚发生了冲突。在命令行上,我知道如何处理这个问题,但 GitHub for Windows 选择让我处于我不熟悉的状态:

C:\Users\w\Documents\GitHub\CmisSync [(6026d18...)|REBASE +0 ~1 -0 !1 | +0 ~0 -0 !1]> git status
# Not currently on any branch.
# You are currently rebasing.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
...

I fixed the conflict, committed the files, but when I run git pushI am told:

我解决了冲突,提交了文件,但是当我运行时,git push我被告知:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD) state now, use

    git push origin HEAD:<name-of-remote-branch>

What is the recommended way to get my merging commits to the remote master?
I doubt git push origin HEAD:masterwill achieve this.

将我的合并提交提交给远程主服务器的推荐方法是什么?
我怀疑git push origin HEAD:master是否会实现这一目标。

回答by mgarciaisaia

As we where saying with Simon Boudrias, if you don't really know what you've done during a rebase, the best thing to start off is with a git rebase --abort. As the verb says, it aborts the current rebase, and leaves you with your repository and working copy in the same state it was before the rebase started.

正如我们与Simon Boudrias所说的那样,如果您真的不知道在 rebase 期间您做了什么,那么最好的开始是使用git rebase --abort. 正如动词所说,它会中止当前的 rebase,并使您的存储库和工作副本处于 rebase 开始之前的相同状态。

After that, you should do whatever you've done that started the rebase process (I don't think you said what it was, but don't think it's really important, either). Surely the rebase will start again, and here is where your original question begins to be answered.

在那之后,你应该做任何你做过的启动 rebase 过程的事情(我认为你没有说它是什么,但也不要认为它真的很重要)。当然,rebase 将再次开始,这里是您最初的问题开始得到回答的地方。

As the status output says, you seem to have conflicts. You should resolve them (I usually use git status --shortplus git mergetoolto resolve them with meld), then git addthe files. When status is OK (say, every file that would have to be commited is added, with no conflicts), you should git rebase --continueinstead of git commit.

正如状态输出所说,您似乎有冲突。您应该解决它们(我通常使用git status --shortplusgit mergetool来解决它们meld),然后git add是文件。当状态正常时(比如,每个必须提交的文件都被添加,没有冲突),你应该git rebase --continue而不是git commit.

The idea is that git rebaseapplies a group of commits on top of a given commit. I don't really know what commits are being applied on top of what, but it's important to have that in mind. Keep in mind that there can show multiple conflicts, because commits apply one by one. Use git logto see what was the last commit applied, and I think there has to be a file in your .git/directory with the commit message of the commit that's currently being applied.

这个想法是git rebase在给定的提交之上应用一组提交。我真的不知道在什么之上应用了什么提交,但记住这一点很重要。请记住,可能会出现多个冲突,因为提交是一项一项的。使用git log去看个究竟,最后提交申请,我认为必须有在你的文件.git/目录中的,因此目前正在应用的提交的提交信息。

It's a commmon newbie error (we've all been there :)) to try to include changes in the files during the conflict resolution without knowing (or forgetting) they were going to be applied by a latter commit.

这是一个常见的新手错误(我们都遇到过:))在冲突解决期间尝试在文件中包含更改而不知道(或忘记)它们将被后一次提交应用。

So, hopefully, after resolving some conflicts, adding the files and git rebase --continueing them, you should arrive to a happy functional repository, and you'll be able to git pushfrom there on.

因此,希望在解决了一些冲突、添加文件并对其进行git rebase --continueing 之后,您应该会到达一个愉快的功能存储库,并且您将能够git push从那里开始。

Lastly, but not least important: after all the rebase stuff, use git logto check you're not modifying any public commit. Say, that your new branch contains the remote's HEAD commit. Rebasing is powerful and very dangerous. You don't want to rebase a public commit - it's maybe the only git pain you don't want to face :)

最后,但同样重要的是:在所有 rebase 之后,用于git log检查您没有修改任何公开提交。假设您的新分支包含远程的 HEAD 提交。变基很强大,也很危险。您不想重新设置公开提交 - 这可能是您不想面对的唯一 git 痛苦:)

回答by Simon Boudrias

You first need to end the rebasemode by calling git rebase --continueonce you resolved your conflicts. This should then put you back on the branch you were pulling (in your case master). You'll notice this happens when the command line (posh-git plugin) will indicates masterinstead of REBASE

一旦您解决了冲突,您首先需要rebase通过调用来结束该模式git rebase --continue。这应该让你回到你正在拉的分支(在你的情况下)。您会注意到当命令行(posh-git 插件)将指示master而不是REBASE

Then you could push using git push origin master. The extra parameters may be autofilled by Git, but that'll depends on your settings.

然后你可以使用git push origin master. Git 可能会自动填充额外的参数,但这取决于您的设置。