LoginSignup
6
4

More than 5 years have passed since last update.

git subtree で最初に add エラーが発生する対応

Last updated at Posted at 2016-12-21

Stylez Advent Calendar 2016 - Qiita
http://qiita.com/advent-calendar/2016/stylez

株式会社スタイルズの Adventカレンダー 21日目です。

git subtree addでハマったメモ - Qiita
http://qiita.com/tutui/items/7f39b32a93df5c82fdc3

と同じですが。。

subtreeを使っていていつもやってしまうので、メモです。

1. Gitlab でレポジトリを作成します。

(割愛)

2. Gitlabからクローンします。

bash
$ git clone git@XXXXXXX:project-XXXXX/XXXXXXX.git
Cloning into 'XXXXXXX'...
  rning: You appear to have cloned an empty repository.
Checking connectivity... done.

何の問題もなく終わる。

3. Subtree側のGitレポジトリを追加します。

bash
$ git remote add -f XXXXXXX-base git@XXXXXXX:base-XXXXX/base-ansible.git
Updating XXXXXXX-base
remote: Counting objects: 1735, done.
remote: Compressing objects: 100% (1292/1292), done.
remote: Total 1735 (delta 707), reused 585 (delta 188)
Receiving objects: 100% (1735/1735), 9.61 MiB | 10.36 MiB/s, done.
Resolving deltas: 100% (707/707), done.
From XXXXXXX:base-XXXXX/base-ansible
 * [new branch]      master     -> XXXXXX-base/master

これも問題ない。

4. subtreeのGitレポジトリをroleディレクトリに出力

bash
$ git subtree add --prefix=roles --squash XXXXXX-base master
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Working tree has modifications.  Cannot add.

こんなエラーが出ます。
理由は、まだローカルのレポジトリに何もないので、addする先(ブランチ)がない。
#のだと思う。

5. 対処法

何でも良いので、1つコミットします。

bash
$ echo '*.swp' >> .gitignore
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
$ git commit -m 'add initial .gitignore'
$ git push

どうせ必要になる、.gitignoreを追加しました。

6. 再度addします。

bash
$ git subtree add --prefix=roles --squash XXXXXX-base master
git fetch owncloud-base master
From XXXXXXX:base-XXXXX/base-ansible
 * branch            master     -> FETCH_HEAD
Added dir 'roles'

問題なく完了します。

7. ひとまずPushしておきましょう。

bash
$ git push
Counting objects: 463, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (310/310), done.
Writing objects: 100% (463/463), 9.49 MiB | 0 bytes/s, done.
Total 463 (delta 44), reused 420 (delta 34)
To git@XXXXXXX:project-XXXXX/XXXXXXX.git
   abadefb..f2a0b9f  master -> master

良い感じです。

6
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4