git rebase fatal:需要一次修订

发布于 2024-10-14 16:23:31 字数 522 浏览 5 评论 0原文

我有一个公共存储库的分支,我正在尝试使用原始存储库中的当前提交更新我的分支:

$ git fetch <remote>
remote: Counting objects: 24, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 20 (delta 12), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
From git://github.com/path_to/repo
  9b70165..22127d0  master     -> $/master
$ git rebase <remote>
fatal: Needed a single revision
invalid upstream <remote>

代替了我的远程名称,实际上并不是我的远程姓名。关于此错误的文档似乎有点松散。

I have a branch of a public repository and I am trying to update my branch with the current commits from the original repository:

$ git fetch <remote>
remote: Counting objects: 24, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 20 (delta 12), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
From git://github.com/path_to/repo
  9b70165..22127d0  master     -> $/master
$ git rebase <remote>
fatal: Needed a single revision
invalid upstream <remote>

The <remote> is in place of my remote name and is not actually my remote name. The documentation on this error seems to be a bit loose.

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

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

发布评论

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

评论(8

泪是无色的血 2024-10-21 16:23:31

您需要提供分支的名称(或其他提交标识符),而不是 git rebase 的远程名称。

例如:

git rebase origin/master

不是:

git rebase origin

注意,虽然 origin 在用作需要提交引用的参数时应该解析为 ref origin/HEAD,但似乎并不是每个存储库都会获得这样的参考,所以它可能不起作用(在你的情况下不起作用)。明确是值得的。

You need to provide the name of a branch (or other commit identifier), not the name of a remote to git rebase.

E.g.:

git rebase origin/master

not:

git rebase origin

Note, although origin should resolve to the the ref origin/HEAD when used as an argument where a commit reference is required, it seems that not every repository gains such a reference so it may not (and in your case doesn't) work. It pays to be explicit.

北笙凉宸 2024-10-21 16:23:31

检查您分支名称的拼写是否正确。我正在重新调整故事分支(即 branch_name)并忘记了故事部分。 (即story/branch_name)然后 git 向我吐出这个错误,这在这种情况下没有多大意义。

Check that you spelled the branch name correctly. I was rebasing a story branch (i.e. branch_name) and forgot the story part. (i.e. story/branch_name) and then git spit this error at me which didn't make much sense in this context.

一抹微笑 2024-10-21 16:23:31

我遇到了致命:需要一次修订并意识到我在尝试变基之前没有获取上游。我所需要的只是首先git fetch uploaded

I ran into fatal: Needed a single revision and realized I didn't fetch the upstream before trying to rebase. All I needed was to git fetch upstream first.

挽心 2024-10-21 16:23:31

问题是您从...分支出一个分支,您试图重新定位到该分支。您无法变基到不包含最初创建当前分支的提交的分支。

当我第一次将本地分支 X 重新基化为推送的 Y,然后尝试将分支(首先在 X 上创建)重新基化为推送的 Y 时,我得到了这个问题。

通过重新基址到 X 解决了我的问题。

重新基址到远程没有问题分支(可能甚至没有签出),前提是我当前的分支源于该分支的祖先。

The issue is that you branched off a branch off of.... where you are trying to rebase to. You can't rebase to a branch that does not contain the commit your current branch was originally created on.

I got this when I first rebased a local branch X to a pushed one Y, then tried to rebase a branch (first created on X) to the pushed one Y.

Solved for me by rebasing to X.

I have no problem rebasing to remote branches (potentially not even checked out), provided my current branch stems from an ancestor of that branch.

八巷 2024-10-21 16:23:31

当您的存储库没有为远程设置默认分支时,就会出现此错误。您可以使用 git remote set-head 命令修改默认分支,从而能够使用远程名称而不是该远程中的指定分支。

查询远程(在本例中为 origin)的 HEAD(通常为 master),并将其设置为默认分支:

$ git remote set-head origin --auto

如果您想要要在本地使用不同的默认远程分支,您可以指定该分支:

$ git remote set-head origin new-default

设置默认分支后,您可以在 git rebase和任何其他命令中仅使用远程名称,而不是显式使用<远程>/<分支>

在幕后,此命令会更新 .git/refs/remotes/origin/HEAD 中的引用。

$ cat .git/refs/remotes/origin/HEAD 
ref: refs/remotes/origin/master

有关更多详细信息,请参阅 git-remote 手册页

The error occurs when your repository does not have the default branch set for the remote. You can use the git remote set-head command to modify the default branch, and thus be able to use the remote name instead of a specified branch in that remote.

To query the remote (in this case origin) for its HEAD (typically master), and set that as the default branch:

$ git remote set-head origin --auto

If you want to use a different default remote branch locally, you can specify that branch:

$ git remote set-head origin new-default

Once the default branch is set, you can use just the remote name in git rebase <remote> and any other commands instead of explicit <remote>/<branch>.

Behind the scenes, this command updates the reference in .git/refs/remotes/origin/HEAD.

$ cat .git/refs/remotes/origin/HEAD 
ref: refs/remotes/origin/master

See the git-remote man page for further details.

他不在意 2024-10-21 16:23:31

对我来说,指定分支有帮助。

  1 [submodule "test/gtest"]
  2     path = test/gtest
  3     url = ssh://[email protected]/google/googletest.git
  4     branch = main

For me, to specify branch helps.

  1 [submodule "test/gtest"]
  2     path = test/gtest
  3     url = ssh://[email protected]/google/googletest.git
  4     branch = main
极致的悲 2024-10-21 16:23:31

git 子模块 deinit --all -f
为我工作。

git submodule deinit --all -f
worked for me.

无人问我粥可暖 2024-10-21 16:23:31

$ git rebase upper/master

fatal: Needed a single revision

invalid upper usptream/master**

所以我尝试了 $ git rebaseremotes/upstream/master 它对我有用。

$ git rebase upstream/master

fatal: Needed a single revision

invalid upstream usptream/master**

So I tried $ git rebase remotes/upstream/master and it works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文