BFG を使用してリポジトリを Git LFS へ移行する
BFG and the BFG Repo-Cleaner are third-party utilities that are not supported by Atlassian. The material provided in this support document is for educational purposes only and is not intended to be a process or resource that is supported by Atlassian or Bitbucket Cloud. Have questions? Please check the Git LFS support release notes or the BFG Repo-Cleaner page.
以下についてご理解ください。
BFG はリポジトリの Git 履歴を完全に書き換えます。
移行プロセスがすべて完了するまである程度の時間を要する場合があります。移行中は、ご本人とワークスペースのどのメンバーも既存のリポジトリで作業を行うことができません。
サイズがローカルで縮小された場合でも、BFG を使用して Git LFS に移行したからといって Bitbucket Cloud で報告されるリポジトリのサイズが縮小される保証はありません。これは、マージされたプル リクエストの差分を保存するために、クローンでは表示されない Git コミットへの追加の参照が Bitbucket Cloud によって保存されるためです。これらの参照を特定して Bitbucket Cloud ストレージから削除するには、当社のサポート チームまでご連絡いただく必要があります。参照を削除すると、過去のプル リクエスト データが削除される可能性があることに注意してください。
When you want to use the Git LFS extension with large files that already exist in a Bitbucket repo, just tracking those large files does not convert them to LFS files. Because the large files are still part of the Git history, the only way to convert those files is to rewrite the history.
This page describes the three stages involved when using bfg-repo-cleaner to change the Git history of a repo in Bitbucket.
移行を開始する前に次の点をご確認ください。
変換するファイルに対して十分な LFS ストレージがあること。ファイルの現在のバージョンと履歴に含まれる過去のすべてのバージョンに対応できる必要があります。
リポジトリへのアクセス権を持つすべてのユーザーが「すべての変更」をプッシュ済みであること。プッシュされていない変更をあとからマージすることはできません。
移行中はリポジトリ権限を調整してプッシュを禁止すること。
You have the Java Runtime Environment (Java 7 or above) installed on your local machine.
You've downloaded latest BFG version from https://rtyley.github.io/bfg-repo-cleaner/.
Have questions? Please check the Git LFS support release notes or the BFG Repo-Cleaner page.
A. リポジトリの既存のファイルの Git LFS への変換
ターミナルで以降のすべてのコマンドを実行します。
1. リポジトリのクローン
git clone --mirror git@bitbucket.org:<username>/<repo-name>.gitmirror フラグでクローンを行うと、ベア リポジトリが作成されます。これを行うと、ユーザーや同僚のすべてのブランチを取得できます。
<repo-name>.git という名前のフォルダが作成されます。
2. クローンされたリポジトリのバックアップ
<repo-name>.git フォルダのバックアップを作成し、問題が発生した場合にこのバージョンに戻れるようにします。
3. BFG での Git 履歴の書き換え
Make sure you've downloaded latest BFG version from https://rtyley.github.io/bfg-repo-cleaner/.
ダウンロードした bfg-x.x.x.jar ファイルのロケーションへの絶対パスを使用します。
java -jar <path to>bfg-x.x.x.jar --convert-to-git-lfs "*.{png,mp4}" --no-blob-protection <repo-name>.gitこの例では png ファイルと mp4 ファイル タイプを変換していますが、他のファイル タイプも同様に変換できます。
これは全ブランチの全履歴を書き換え、すべての png および mp4 ファイルを LFS バージョンで置き換えます。
4. Git LFS の初期化
cd <repo-name>.git
git lfs installこれは、ベア リポジトリに pre-push hook を追加します。
5. 変換したリポジトリを Bitbucket にプッシュして戻す
git push --forceこれはすべての大容量ファイルを LFS ストレージにプッシュし、新しく書き換えた履歴で Git 履歴を上書きします。
Have questions? Find more on the BFG Repo-Cleaner page or the Git LFS support release notes.
B. Git LFS での以降のトラッキングのセットアップ
1. 変換したリポジトリを Bitbucket からクローン
git clone git@bitbucket.org:<username>/<repo-name>.git前述の手順で変換した Git リポジトリをクローンします。
2. Git LFS でのファイルのトラッキング
See set up Git LFS file tracking locally.
C. ワークスペースのメンバーによる更新されたリポジトリへの変更の許可
Each person needs to have installed the Git LFS extension locally. See the instructions on Use Git LFS with Bitbucket.
その後、ユーザーはローカルにあるリポジトリの既存のクローンを削除して、LFS が有効化された新しいバージョンをクローンする必要があります。
git clone git@bitbucket.org:<username>/<repo-name>.gitこの内容はお役に立ちましたか?