我尝试使用哈希在Git服务器上创建一个新的分支,但也不在本地创建分支:
$ git push origin HEAD^:new-branch
error: unable to push to unqualified destination: new-branch
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'git@github:company/repo.git'
当您强制推过现有分支时,这会起作用。我已经试过到达目的地了
refs/new-branch
上面写着:
$ git push origin HEAD^:refs/new-branch
Total 0 (delta 0), reused 0 (delta 0)
remote: error: refusing to create funny ref 'refs/new-branch' remotely
To github.com:company/repo.git
! [remote rejected] HEAD^ -> refs/new-branch (funny refname)
error: failed to push some refs to 'git@github.com:company/repo.git'
对于尚未存在的目的地,其格式是什么?
我要这样解决它
$ git branch new-branch
$ git push origin new-branch
$ git push origin HEAD^:new-branch -f
$ git branch -D new-branch
或者像这样
$ git branch new-branch HEAD^
$ git push origin new-branch
$ git branch -D new-branch
但是,它应该知道如何在服务器上创建一个新的分支,而不需要在本地创建它。