【Git】Pods を外して新しいリポジトリで管理する

先週公開した 【Git】GitHub 管理下にある Pods を外す では、リポジトリをそのままで Pods を外しました。
今回の記事では、前回同様 GitHub 管理下にある Pods だけを外し、新しいリポジトリで Pods を管理しない状態にしたいと思います。

同じリポジトリでもよかったのですが、前のバージョンに戻すことってほとんどなくて…特に個人開発だと顕著に (´・ω・`;A
数ヶ月ぶりにアップデートするアプリがあったので、新しいリポジトリで管理してみようかなと!

開発環境(前提条件)

・macOS BigSur(ver11.1)
・Xcode12.4
・CocoaPod(Carthage不使用)
・GitHub(Pods配下もプッシュ済み)

さっそく作業ォ

新しいリポジトリはすでに作成しているものとします!
ブラウザぽちぽちでイケますし、説明めんどいので。笑

リモートURLを変更する

ターミナルを起動して、対象のリポジトリに移動して、リモートURL を変更します。
URL は新しいリポジトリを作成した画面でコピってください。(以下、new-remote-url とします)

% git remote -v                             // まずは現在のリモートURLを確認
// origin   https://github.com/YourAccount/YourProject.git (fetch)
// origin   https://github.com/YourAccount/YourProject.git (push)
% git remote set-url origin new-remote-url  // 新しいリポジトリのURLを設定する
% git remote -v                             // もう一度リモートURLを確認
// origin   origin new-remote-url (fetch)
// origin   origin new-remote-url (push)

URLが変更されていたら OK です。

管理外にしたいファイルを指定する

git の管理外にしたいファイルを指定するために、ターミナルで .gitignore というファイルを作成します。
このファイルに書かれたファイルは Git のトラッキング対象外になるので、Pods もここで指定します。

% vi .gitignore   // エディタモードで .gitignore を作成

エディタモードに切り替わったら、i を押して入力モードにします。
コードはテンプレートがあるので、そこから一部を抜粋します。

# Mac
.DS_Store

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
*.xcworkspace

コピペしたら esc を押して入力モードを終了 → :wq を入力してファイルを保存します。

Git を再設定

新しいリポジトリには、これまでの Git の履歴は引き継ぎたくないので初期化します。

% git init                               // Gitを初期化
% git remote add origin new-remote-url   // 新しいリポジトリのURLを設定

//----- 新しいリポジトリでプロジェクトを管理する -----//

% git add .
% git commit -m "コミットメッセージを記入"
% git push origin master

これで Git の再設定は完了です!
以降はいつも通りブランチ切ったりコミットしたりしてください。

あと、GitHub でリポジトリ見たら Pods は管理されていない状態になっていると思います!

さいごに

同じリポジトリでやるのとは大違い…超絶イージーモード!

足並み揃えられるなら、中規模プロジェクトでも新しいリポジトリでやっていいと思うなぁ
Git 管理下から Pods を削除すると、全履歴に変更かけないといけないし。

というか中規模以上になると足並み揃えるのも大変か (‘・c_・` ;

Git
スポンサーリンク

コメント