【问题标题】:Completely replace remote branch with another in github leaving no traces of the old one完全用 github 中的另一个分支替换远程分支,不留旧分支的痕迹
【发布时间】:2013-03-29 22:16:50
【问题描述】:

我将一个分支推送到一个空的 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.

我不得不删除 repo 并重新推送我的新分支。那行得通,但让我想知道:

  1. 我应该怎么做才能完全替换远程分支 其他 ?

  2. 为什么我得到了 ssh:连接到主机端口 22: Bad file number 错误 - 当我第一次推送成功时(注意我在 http 上)?

    $ git --version
    git version 1.8.1.msysgit.1
    

【问题讨论】:

    标签: git ssh push


    【解决方案1】:

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

    git push -f github GitHubSquash
    

    这会将远程 GitHubSquash 分支替换为您的本地版本。如果你只想删除远程分支:

    git push -f github :GitHubSquash
    

    我猜你弄错了,因为 git 试图将 :github 解释为 url 并且发生了奇怪的事情:)。

    【讨论】:

      【解决方案2】:
      git push origin :GitHubSquash
      

      删除远程分支

      git push --set-upstream origin GitHubSquash
      

      推送本地分支

      【讨论】:

        猜你喜欢
        • 2021-08-30
        • 2012-03-01
        • 2011-02-21
        • 2015-10-19
        • 1970-01-01
        • 1970-01-01
        • 2019-12-25
        • 2015-08-08
        相关资源
        最近更新 更多