gitのorphanブランチを理解する
Github Pagesに使えそうなのでmanの該当箇所を訳してみました*1。=>原文
orphanブランチというのは、元のブランチからの歴史を受け継がず、gitリポジトリ内で新しく0から歴史を持つブランチです。新しくルートになり、親コミットを持ちません。
リポジトリの中から特定のファイルのみを公開したい場合などに使えそうです。
# 日本語として自然になるように努力はしてませんが、間違いは指摘していただければ直します
Synopsis
git checkout [-q] [-f] [-m] [[-b|-B|--orphan]
Description
Create a new orphan branch, named
新しく
この新しいブランチ上での最初のコミットは親を持たず、他の全てのブランチとコミットから完全に切り離されている新しい歴史のルートになる。
The index and the working tree are adjusted as if you had previously run "git checkout
あなたが直前に "git checkout
これは
This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.
これは、コミットから完全な歴史を暴露することなく、ツリーを公開したいときに便利に使える。
あなたはこれを行うことで、カレントツリーが "クリーン" なあるプロジェクトのオープンソースブランチを公開したいかも知れない、しかしその完全な歴史には
プロプライエタリまたは他の阻害されるコードを含んでいる。
If you want to start a disconnected history that records a set of paths that is totally different from the one of
then you should clear the index and the working tree right after creating the orphan branch by running "git rm -rf ." from the top level of the working tree.
Afterwards you will be ready to prepare your new files, repopulating the working tree, by copying them from elsewhere, extracting a tarball, etc.
''orphan'' ブランチを作成した直後に ワーキングツリーのトップレベルから "git rm -rf ."を実行することで インデックスとワーキングツリーをクリアするべきである。
その後、新しいファイルの準備が出来たら、それらを他の場所からコピーし、tarballを展開し、etcすることでワーキングツリーを再度成長させる。
新しく歴史を始めるブランチを作るまとめ
- --orphan を指定してcheckout
- git checkout --orphan
- git checkout --orphan
- 今までのブランチで管理しているファイルを消す
- git rm -rf .
- 新しく管理するファイルをadd, commit
*1:結局自分で訳してみるのが早いんだよなぁ…