“您当前不在分支机构中"尝试与上游存储库同步派生时发生错误 [英] "You are not currently on a branch" error when trying to sync fork with upstream repository

查看:245
本文介绍了“您当前不在分支机构中"尝试与上游存储库同步派生时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了 GitHub存储库的分支.我修复了一个错误,编写了测试并创建了合并到原始存储库中.

I made a fork of a GitHub repository. I fixed a bug, wrote a test and created a pull request which was merged into the original repository.

到目前为止,太好了.

So far, so good.

现在,我改进了本地计算机上的测试.我想通过此改进的测试创建一个新的请求请求.但是与此同时,还对原始上游存储库进行了其他提交.因此,我想使fork与上游存储库同步,以便创建新的请求请求.

Now I improved the test on my local machine. I want to create a new pull request with this improved test. But in the meantime, other commits have been made to the original, upstream repository. So I want to get my fork into sync with the upstream repository so that I can create the new pull request.

在没有完全掌握我在做什么的情况下,我一直在从其他StackOverflow答案中复制/粘贴git命令.但是我无法使它正常工作.

Without fully grasping what I was doing, I've been copy/pasting git commands from other StackOverflow answers. But I can't get it to work.

这是当前情况:

$ 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>
$ git status
rebase in progress; onto 4378fa4
You are currently rebasing branch 'master' on '4378fa4'.
  (all conflicts fixed: run "git rebase --continue")

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        Tests/.vscode/

nothing added to commit but untracked files present (use "git add" to track)

或视觉上:

$ git log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
* 46f5c0e (HEAD) Change to non-UTF8 locale C (ASCII only) inside test (BioGeek, 3 hours ago)
| *   fe24176 (master) merge changes from upstream (BioGeek, 3 days ago)
| |\
| |/
|/|
* | 4378fa4 (upstream/master) Thank Jerven for ExPASy URL updates (Peter Cock, 3 days ago)
* | 03de45c Update ExPASy tests for HTTPS (Peter Cock, 3 days ago)
* | 47cdbf7 Move expasy URLs to https (Jerven Bolleman, 4 days ago)
* | 9bfb8b1 replace expasy.ch by expasy.org (Jerven Bolleman, 4 days ago)
* | 1a32c50 Determine encoding for urllib handles from HTTP headers (Jeroen Van Goey, 3 days ago)
* | ccf88fc Tests do not require postgresql CREATE DATABASE permissions (Adhemar Zerlotini, 3 days ago)
| | *   6b7d235 (refs/stash) WIP on master: 6311677 remove Doc/examples/tree1.nwk which was committed accidentally (created during testing?) (BioGeek, 3 days ago)
| | |\
| |/ /
| | * 4ead5fa index on master: 6311677 remove Doc/examples/tree1.nwk which was committed accidentally (created during testing?) (BioGeek, 3 days ago)
| |/
| * 6311677 (origin/master, origin/HEAD) remove Doc/examples/tree1.nwk which was committed accidentally (created during testing?) (BioGeek, 3 days ago)
| * 41ff4cc Address flake8 warnings (BioGeek, 3 days ago)
| * 815bbfd Add encoding and prefic unicode string with 'u' (BioGeek, 3 days ago)
| * 0e7451d If the handle has a headers attribute, then use it's content charset as encoding. Otherwise fall back to the default behaviour. (BioGeek, 4 days ago)
| * 6a7d05b Add test for correct handling of encodings in Entrez.efetch. Also add some missing docstrings in other tests and close handles everywhere (BioGeek, 4 days ago)
|/
* 4ccdace mmCIF parser fix to check for both '?' and '.' as unassigned values (Joao Rodrigues, 5 days ago)

Changeset 46f5c0e是我要从中创建新的请求请求的改进测试.

Changeset 46f5c0e is the improved test from which I want to create a new pull request.

如何使fork与上游存储库同步,以便创建新的请求请求?

How do I get to sync my fork with the upstream repository so that I can create the new pull request?

推荐答案

如git的一些有用的错误消息所述:

As stated in git's somewhat helpful error message:

$ git status
rebase in progress; onto 4378fa4
You are currently rebasing branch 'master' on '4378fa4'.
  (all conflicts fixed: run "git rebase --continue")

继续进行基础调整

这意味着您可能是上游的git pull -r,或者正在将一个分支重新定位到本地的另一个分支, ,并且在尝试自动合并时遇到了问题(可能是合并冲突).

Continue rebasing

This means you have probably git pull -r from your upstream, or are rebasing a branch onto another branch locally, and you have encountered a problem while attempting to automatically merge (likely a merge conflict).

当git在尝试快速转发时遇到合并冲突时,它将停止重新设置基础并等待用户手动解决问题.

When git encounters a merge conflict while attempting to fast-foward, it stops rebasing and waits for the user fix the problem manually.

完成后,您需要暂存已修复的更改的文件(使用git add <pathspec>),但不提交.暂存文件后,git将在您git rebase --continue时知道您所做的更改并尝试将其集成.

Once that is done, you need to stage the changed files you fixed (with git add <pathspec>) but not make a commit. Once the file is staged, git will be aware of your changes and attempt to integrate them when you git rebase --continue.

保持修复问题,然后按git rebase --continue直到完成.这会将您的HEAD移动到工作分支的尖端.然后,您可以进行推送.

Keep fixing problems and git rebase --continue until you are done. This will move your HEAD to the tip of your working branch. You can then push.

您可以git rebase --abort放弃整个操作,这还将撤消沿途所做的任何修复,并尝试另一种合并策略,例如3向合并.

You can git rebase --abort to abandon the whole thing, which will also undo any fixes you have made along the way, and try another merge strategy, like a 3-way merge.

与快速转发相比,三向合并的一个优点是所有合并冲突都将在同一时间显示,您可以使用所有修复程序创建一个新的合并提交.但是,在快速转发时,您可能需要停止几次以解决冲突,因为git在将连续的提交应用于工作分支时遇到了冲突.

One advantage of a three-way merge over a fast-forward is that all of the merge conflicts will be presented at the same time and you can create a new merge commit with all the fixes. While fast-forwarding, however, you may need to stop several times to fix conflicts as git encounters them while applying successive commits to your working branch.

给出

在没有完全掌握我在做什么的情况下,我一直在从其他StackOverflow答案中复制/粘贴git命令.但是我无法使它正常工作.

Without fully grasping what I was doing, I've been copy/pasting git commands from other StackOverflow answers. But I can't get it to work.

我会git rebase --abort并从头开始.如果您停止了很多次并且不得不解决许多合并冲突,则可以使用git pull --no-ff <remote-name> <local-branch>明确指示git即使可以,也不要尝试快速转发.

I would git rebase --abort and start from scratch. If you stopped many times and had to fix many merge conflicts, you could use git pull --no-ff <remote-name> <local-branch> to explicitly instruct git not to try a fast forward, even if it can.

如果历史记录难以处理且更改很小,则始终可以搁置"更改,这意味着将更改后的文件的版本复制到桌面上

If the histories are just unmanageable and your change is small, you can always "shelve" your changes, meaning copy your version of the changed files to your desktop and then overwrite your local branch with the exact content of the upstream. Then, just copy the changed files back into your repo and make a commit.

这不是一个很好的解决方案,但是它可以工作,有时比管理悠久的历史要容易得多.但是您将丢失自己的提交.有一种方法可以保留它们修补,如果您真的有兴趣.

It is not an elegant solution, but it works and is sometimes far easier than managing a long history. But you will lose the commits you had. There is a way to preserve them with patching, if you're really interested.

有关 HEAD的含义的详细信息.

这篇关于“您当前不在分支机构中"尝试与上游存储库同步派生时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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