"您目前不在分支机构"尝试与上游存储库同步fork时出错

时间:2017-10-30 14:22:53

标签: git github rebase git-fork

我做了a fork of a GitHub repository。我修复了a bug,编写了一个测试并创建了a pull request merged到原始存储库中。

到目前为止,这么好。

现在我在本地计算机上改进了测试。我想用这个改进的测试创建一个新的pull请求。但与此同时,对原始的上游存储库进行了其他提交。所以我想让我的fork与上游存储库同步,以便我可以创建新的pull请求。

在没有完全掌握我正在做的事情的情况下,我已经从其他StackOverflow答案中复制/粘贴git命令。但我无法让它发挥作用。

以下是目前的情况:

$ 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)

变更集46f5c0e是我想要创建新拉取请求的改进测试。

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

1 个答案:

答案 0 :(得分:3)

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

$ 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,或者正在将分支重新定位到本地的另一个分支,您在尝试自动合并时遇到问题(可能是合并冲突) )。

当git在尝试快速转发时遇到合并冲突时,它会停止重新定位并等待用户手动修复问题。

完成后,您需要暂存已修复的已更改文件(使用git add <pathspec>)但不进行提交。文件暂存后,git会知道您的更改,并尝试在git rebase --continue时集成它们。

继续修复问题和git rebase --continue,直到完成为止。这会将您的HEAD移动到工作分支的顶端。然后你可以推。

替代地

您可以git rebase --abort放弃整个事情,这也将撤消您在此过程中所做的任何修复,并尝试其他合并策略,例如3合并。

快进的三向合并的一个优点是所有合并冲突将同时出现,您可以创建一个包含所有修复的新合并提交。但是,在快速转发时,您可能需要多次停止修复冲突,因为git会在向您的工作分支应用连续提交时遇到冲突。

我的个人意见

给出

  

在没有完全掌握我正在做的事情的情况下,我一直在从其他StackOverflow答案中复制/粘贴git命令。但我无法让它发挥作用。

我会git rebase --abort从头开始。如果您多次停止并且必须修复许多合并冲突,您可以使用git pull --no-ff <remote-name> <local-branch>明确指示git不要尝试快进,即使它可以。

最后沟渠选项

如果历史记录难以管理且您的更改很小,您可以随时“搁置”您的更改,即将已更改文件的版本复制到桌面and then overwrite your local branch with the exact content of the upstream。然后,只需将更改的文件复制回您的仓库并进行提交。

这不是一个优雅的解决方案,但它有效,有时比管理悠久的历史要容易得多。但是你将失去你的承诺。如果您真的感兴趣,可以使用preserve them with patching

进一步阅读

更多关于detatched HEAD means

相关问题