完全用另一个远程分支替换Github上的旧分支,不留下任何旧分支的痕迹。

6

我向一个空的 Github 仓库推送了一个分支:

MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
$ git remote add github  https://github.com/Utumno/ted2012.git
MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
$ git push -u github GitHubSquash
Username for 'https://github.com': Utumno
Password for 'https://Utumno@github.com':
//...
To https://github.com/Utumno/ted2012.git
 * [new branch]      GitHubSquash -> GitHubSquash
Branch GitHubSquash set up to track remote branch GitHubSquash from github.

然后我注意到我已经推了一些毛发,试图删除分支或用另一个替换它等等。但是我失败了:

MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHub2)
$ git push  :github && git push github GitHub2
ssh: connect to host  port 22: Bad file number
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHub2)
$ git checkout GitHubSquash
Switched to branch 'GitHubSquash'
Your branch is ahead of 'github/GitHubSquash' by 1 commit.
  (use "git push" to publish your local commits)
MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
$ git push  :github
ssh: connect to host  port 22: Bad file number
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
MrD@MRSD /c/Dropbox/eclipse_workspaces/javaEE/ted2012 (GitHubSquash)
$ git push  -u :github
ssh: connect to host  port 22: Bad file number
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我不得不删除仓库并重新推送我的新分支。这样做成功了,但让我想知道:
  1. What should I have done to completely replace the remote branch with another ?

  2. Why on earth I was getting the ssh: connect to host port 22: Bad file number errors - while my first push succeeded (and notice I am on http) ?

    $ git --version
    git version 1.8.1.msysgit.1
    
2个回答

16

您的语法错误。正确的命令是:

git push -f github GitHubSquash

这将使用本地版本替换远程GitHubSquash分支。如果您只想删除远程分支:

git push -f github :GitHubSquash

我猜你遇到了错误,因为git试图将:github解释为一个URL地址,所以会出现奇怪的问题 :)


0
git push origin :GitHubSquash

删除远程分支

git push --set-upstream origin GitHubSquash

推送本地分支


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接