2015年4月21日火曜日

Qt CreatorでGitを使う

Qt CreatorでGitを使う

【事前準備】
①Gitで管理するディレクトリの作成
例えば以下のようないくつかのプロジェクトを1つでバージョン管理したい場合は、ProjectAフォルダの直下に.gitフォルダができるように以下のようにする。
enter image description here 

$ mkdir /path/to/your/projectA
$ cd /path/to/your/projectA
$ git init
$ git remote add origin git@bitbucket.org:xxxxxxxx/qt.git

②Qt Creatorでプロジェクトを作成する場合のパスは
 /path/to/your/projectA
 とする。するとprojectAフォルダの下に名前で設定したフォルダができる。
 すでにprojectA自身がGitの管理下にあるので、バージョン管理システムに追加はNoneでOK。
 

1. Bitbucketのuser名と登録しているメールアドレスを以下で記載する。

$ git config --list
$ git config --global user.name "user"  
$ git config --global user.email mail.com

2. SSH Keyの登録

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa):← Enter
Created directory '/home/pi/.ssh'. ← ~/.ssh がない場合、ディレクトリを作成します
Enter passphrase (empty for no passphrase): ← Enter
Enter same passphrase again: ← Enter
Your identification has been saved in /home/pi/.ssh/id_rsa.
Your public key has been saved in /home/pi/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:pi@raspberrypi
The key's randomart image is:

「./ssh/id_rsa.pub」の内容をBitbucketのアカウントの管理→SSHキーに登録する

【接続テスト】
以下のようにloggedがでれば接続OK

$ ssh -T git@bitbucket.org
The authenticity of host 'bitbucket.org (131.103.20.167)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org,131.103.20.167' (RSA) to the list of known hosts.
logged in as xxxxxxxx.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

3.クライアント側(Ubuntu)の設定

vi ~/.ssh/config
Host bitbucket.org
  HostName bitbucket.org
  IdentityFile ~/.ssh/id_rsa
  User xxxxxx
  TCPKeepAlive yes
  IdentitiesOnly yes

4. コミット
 Git→ローカルディレクトリ→コミット もしくは、左下のコマンドが打てるところでgitと入力すると
 コミットがでてくるのでそれを選択。
 enter image description here
 
 コミットの画面がでてきたら、すべてを選択にチェックし、説明を記載し、コミットボタンをクリック
enter image description here

5. Qt Creatorで
  ツール→Git→リモートリポジトリ→リモートの管理
  でBitbucketのリポジトリを追加。 ※最初のみでOK
  Pushしたいリモートディレクトリを選択してPush。

Qt CreatorでPushする場合は、最初の1回目は端末で以下を実行し、
2回目からはツール→Git→リモートリポジトリ→PushでOK。


$ cd /path/to/your/projectA
$ git push -u origin master

追記
【事前準備】の①を実行すると以下の追加は不要でした。
  
enter image description here

  HTTPSのほうは、パスワードを聞いてきたが、SSHはパスワードなしでPushできました。

ここでPushしたら以下のようなメッセージがでたので、

$ git config –global push.default matching
を追加

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

これにより、上記のエラーはでなくなったのですが、Pushすると
まだ以下のエラーが残ってました。

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
Everything up-to-date

このエラーは
リモートリポジトリ上にまだmasterブランチが作成されていないためとのこと。
push時の引数が省略された場合、デフォルトではリモートリポジトリとローカルリポジトリの双方に存在するブランチが対象となるため、リモートリポジトリに存在しないブランチをpushする場合は、リポジトリとブランチを明示的に指定する必要があるとのことです。

参考:
http://blog.mizoshiri.com/archives/1327
https://www.atlassian.com/ja/git/tutorial/remote-repositories#!remote
http://www.backlog.jp/git-guide/reference/trouble-shooting.html

0 件のコメント :

コメントを投稿