簡體   English   中英

如何在git clone之后恢復已刪除的分支?

[英]How do I recover deleted branches after git clone?

我有一個本地git存儲庫(從遠程origin分支克隆):

~/foo

我在本地存儲庫中有一些分支:

~/foo$ git branch
*master
branch1
branch2

origin存儲庫有一個我本地沒有的分支branch3 ,我想將它添加到我的本地。 我做了以下,希望branch3將被添加到我的本地存儲庫:

~/foo/..$ git clone -b branch3 --single-branch git@github.com:<localrespository_name>.git

之后,我看到本地branch3中只有branch3

~/foo$ git branch
*branch3

我的branch1branch2在哪里,我branch1如何恢復它們?

我在遠程存儲庫中沒有branch1branch2副本。

如果已經存在遠程分支3,那應該足夠了

git checkout -b branch3 origin/branch3

而不是您使用的克隆命令。

您可能會看到所有分支(包括遙控器)

git branch --all

例如,在linux-stable樹上:

andi@SHARK:~/working_git/linux-stable$ git branch
  master
andi@SHARK:~/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
  andi@SHARK:~/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'
  andi@SHARK:~/working_git/linux-stable$ git branch
     master
   * v4.9
  andi@SHARK:~/working_git/linux-stable$ git log -1
  commit 75353ac8ff437322ca5520b28d9f9b4b41b39bd6
  Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  Date:   Sun Jan 15 13:43:07 2017 +0100

      Linux 4.9.4

現在我們在remote / origin / linux-v4.9.y分支上獲得了本地v4.9分支。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM