2017-02-03 11 views
1

は、私は(リモートorigin支店からクローン化された)ローカルgitリポジトリを持っている:git cloneの後に削除されたブランチを回復するには?

~/foo 

I持っていたローカルリポジトリ内のいくつかの支店:

~/foo$ git branch 
*master 
branch1 
branch2 

originリポジトリは、分岐branch3を持っています私の地元には持っていない、私は私の地元にそれを追加したい。その後

~/foo/..$ git clone -b branch3 --single-branch [email protected]:<localrespository_name>.git 

、私は唯一のローカルレポジトリでbranch3があることを参照してください:私は私のローカルリポジトリに追加されますbranch3を期待して、次のことをやっている

~/foo$ git branch 
*branch3 

branch1branch2どのように回復できますか?

branch1branch2のコピーはリモートリポジトリにありません。

+2

私は[this](http://stackoverflow.com/questions/3640764/can-i-recover-branch-after-its-deletion-in-git)の質問があなたを助けるかもしれないと信じています。そうでない場合(例えば、 '.git'ディレクトリがすでに消去されているなど)、あなたが何かできることは疑問です。 – yeputons

+0

リンクされた回答は私を助けませんでしたが、回復する方法を見つけました。ローカルの私の以前のブランチを見る方法を見つけることができなかったにしても、私は遠慮なく私のリモートリポジトリにそれらをプッシュすることができました: 'git push [email protected]_repository.git branch1'、そして' branch2'も同じです。 – sawa

+1

次回は、 'git checkout branch3'を実行してください。 Gitは自動的にリモートトラッキングを設定します。 – rlee827

答えて

0

リモートbranch3が既に存在する場合、代わりにあなたが使用cloneコマンドの

git checkout -b branch3 origin/branch3

を行うのに十分なされている必要があります。あなたが例に

git branch --all 

と(リモコン含む)すべての分岐が表示されることがあり

、Linuxの安定木に:

[email protected]:~/working_git/linux-stable$ git branch 
    master 
[email protected]:~/working_git/linux-stable$ git branch --all 
* master 
    remotes/origin/HEAD -> origin/master 
    remotes/origin/linux-2.6.11.y 
    remotes/origin/linux-2.6.12.y 
    remotes/origin/linux-2.6.13.y 
    remotes/origin/linux-2.6.14.y 
    <SNIP> 
    remotes/origin/linux-4.9.y 
    remotes/origin/master 
    [email protected]:~/working_git/linux-stable$ git checkout -b v4.9 origin/linux-4.9.y 
    Checking out files: 100% (11425/11425), done. 
    Branch v4.9 set up to track remote branch linux-4.9.y from origin. 
    Switched to a new branch 'v4.9' 
    [email protected]:~/working_git/linux-stable$ git branch 
    master 
    * v4.9 
    [email protected]:~/working_git/linux-stable$ git log -1 
    commit 75353ac8ff437322ca5520b28d9f9b4b41b39bd6 
    Author: Greg Kroah-Hartman <[email protected]> 
    Date: Sun Jan 15 13:43:07 2017 +0100 

     Linux 4.9.4 

今、私たちは、リモート上のローカルv4.9ブランチを得ました/origin/linux-v4.9.yブランチ。

関連する問題