完全用github中的另一个替换远程分支,不留下旧的痕迹

Mr_*_*s_D 6 git ssh push

我把一个分支推到了一个空的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.
Run Code Online (Sandbox Code Playgroud)

然后我注意到我已经推了一些绒毛并试图删除分支/用另一个等替换它.我失败了:

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.
Run Code Online (Sandbox Code Playgroud)

我不得不删除回购并重新推动我的新分支.这工作但让我感到奇怪:

  1. 我应该怎样做才能完全替换另一个远程分支?

  2. 为什么我到了ssh:连接到主机端口22:错误的文件号错误 - 我的第一次推送成功(并注意我在http上)?

    $ git --version
    git version 1.8.1.msysgit.1
    
    Run Code Online (Sandbox Code Playgroud)

Chr*_*ial 15

你的语法错了.正确的命令是:

git push -f github GitHubSquash
Run Code Online (Sandbox Code Playgroud)

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

git push -f github :GitHubSquash
Run Code Online (Sandbox Code Playgroud)

我猜你得到了你的错误,因为git试图将其解释:github为一个url并且奇怪的事情发生了:).