注:以下で説明する複雑な手法は、「クローン」リポジトリが機能しているリポジトリ(つまり、個別のリモートレイアウトを使用してコミットする非ベアリポジトリ)であり、ベア(またはミラー)リポジトリではない場合にのみ必要です。'cloned.git'がベアリポジトリである場合、元の'report.git'リポジトリを回復するgit clone --bare
(または)だけで十分です(たとえば、alinrusが書いたように)。git clone --mirror
デフォルトの構成と「個別のリモート」レイアウトを意味する最新のGitを使用したとすると、「remotes / origin」(または「remotes / report」)名前空間に「report.git」のリモート追跡ブランチがあります。
'report.git'リポジトリを再作成するには、リモートトラッキングブランチから通常のブランチに一度プッシュ(またはフェッチ)し、通常のフェッチrefspecを元に戻す必要があります(少なくともブランチの場合:タグは常にミラーリングされます)。refs/remotes/origin/*:refs/heads/*
したがって、1回のプッシュ(またはフェッチ)のrefspecは、次のようになりますrefs/tags/*:refs/tags/*
。
リカバリセッションの例
元の「report.git」リポジトリに「master」と「next」の2つのブランチが含まれ、タグがないと仮定します(タグは1-1にマップされるため、とにかく問題にはなりません)。
$ git init --bare report.git
# ...
[report.git] $ git branch -a
* master
next
'cloned / .git'リポジトリを'report.git'の通常の(非ベアおよび非ミラー)クローンにしましょう:
$ git clone user@example.com:report.git cloned
Initialized empty Git repository in /tmp/jnareb/cloned/.git/
# ...
[cloned] $ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/next
[cloned] $ git remote show origin
* remote origin
Fetch URL: user@example.com:report.git
Push URL: user@example.com:report.git
HEAD branch: master
Remote branches:
master tracked
next tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
もちろん、あなたの支店のステータス、そしてあなたの地元の支店の数はあなたの状況によって異なるかもしれません。これは単純な例です。
それでは、元のリポジトリ「report.git」を削除するか、名前を変更(脇に移動)して、リカバリ操作をテストしましょう。
$ mv report.git report-copy.git
ここで、「cloned/.git」の最後のフェッチ/プル操作での「report.git」の状態を再確認します。
$ git init report.git # push won't create new repository
# move to 'cloned' repository
[cloned] $ git push user@example.com:report.git 'refs/remotes/origin/*:refs/heads/*'
Counting objects: 12, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (12/12), 839 bytes, done.
Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
warning: updating the current branch
# long warning about pushing into current branch
To user@example.com:report.git
* [new branch] origin/HEAD -> HEAD
* [new branch] origin/master -> master
* [new branch] origin/next -> next
これで、「report.git」と「report-copy.git」が同一である場合に比較できます。'report.git'が非ベアgit reset --hard HEAD
の場合、プッシュは作業ディレクトリを更新しないため(そして、 'report.git'で自分で更新する必要があるためgit checkout
)、異なる可能性がありますが、ベアリポジトリですよね?
HTH(お役に立てば幸いです)。