git rebase fatal: Needed a single revision

后端 未结 6 1229
花落未央
花落未央 2020-12-12 23:04

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 
         


        
相关标签:
6条回答
  • 2020-12-12 23:35

    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.

    0 讨论(0)
  • 2020-12-12 23:40

    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.

    0 讨论(0)
  • 2020-12-12 23:41

    To make origin/master the default branch for remote origin, and thus make git rebase origin work:

    $ echo "ref: refs/remotes/origin/master" > .git/refs/remotes/origin/HEAD
    
    0 讨论(0)
  • 2020-12-12 23:42

    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.

    0 讨论(0)
  • 2020-12-12 23:44

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

    0 讨论(0)
  • 2020-12-12 23:51

    I ran into this and realized I didn't fetch the upstream before trying to rebase. All I needed was to git fetch upstream

    0 讨论(0)
提交回复
热议问题