ラベル git の投稿を表示しています。 すべての投稿を表示
ラベル git の投稿を表示しています。 すべての投稿を表示

2015年11月7日土曜日

AndroidStudioとBitBucket

AndroidStudioとBitBucket

Android StudioとBitBucketでのソースの管理に関して備忘録として残しておきます。

準備編

1.Bitbucketeでリポジトリを作成
2.以下のコマンドをGitで管理したいフォルダで実行

$mkdir /path/to/your/project
$cd /path/to/your/project
$git init
$git remote add origin git@bitbucket.org:abetakashi/git.git

3.Android Studioでプロジェクトを作成し、上記のフォルダに保存
4.VCS->Enable Version Control Integrationを選択し、Version Control SystemでGitを選択。
  enter image description here
  
5.表示をprojectに切り替えて、右クリック -> Git -> Add
enter image description here

最初のCommit&Push

1.Version ControlタブのLocal Changeタブでdefaultにコミットしたい項目が入っていることを確認し、VCSボタンをクリック
  enter image description here
2.Perform code analysisとCheck TODOのチェックをはずし、コミットメッセージを記載して、Commit and Push。
 masterにコミットされる。
 enter image description here enter image description here

修正分のCommit&Push

コードを修正し、くぎりのよいところで節目として残したい場合は、最初のCommit同様にVCSボタンを押して、Commit and Push。
Logを見るとちゃんと追加されている。
enter image description here

あるところまで戻したい場合

もどしたいコミットを選択し、右クリックし、Checkout Revisionを選択。
enter image description here
右下のGitの表示がmasterから指定したRevisionのコードと、HEADの位置も変わっている。
enter image description here enter image description here

戻したところから再度修正し、Commit&Pushをしようとすると以下のような警告がでるので、戻ったところからブランチする。
enter image description here

ブランチの仕方

先ほど戻したRevisionで右クリックし、New Branchをクリックし、ブランチ(TEST1)を作成する。
enter image description here

これにより、masterからTEST1ブランチに移動している。
enter image description here enter image description here

この状態で先ほどの修正をCommit&Push。
コミット1追加からブランチされて修正が反映されている。
enter image description here

マージの仕方

先ほどTEST1ブランチで修正した内容をmasterにマージしたい場合は、以下の通りLocal Branchesのmaster -> origin/masterを選択してMerge

enter image description here

Conflictsしていたのでファイルを修正し、再度そのファイルを選択してGit -> Add後、Commit & Push

enter image description here

マージはされたがTEST1をmasterにマージしたのではなく、masterがTEST1にマージされたっぽい。

RESETやREVERTをやってみたがうまく戻せないのでもう一度ブランチ(TEST4)を作ってMASTERをチェックアウトし、TEST4を選択してMARGEとすることでmasterにマージできました。

enter image description here

うまくマージができたのでTEST4は削除されたみたいです。
enter image description here

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

2015年4月20日月曜日

Qt CreatorにてGit Cloneを実行する

Qt CreatorにてGit Cloneを実行する

別のパソコンからBitbucketへcommitしたリポジトリをQc Creatorに
クローンする方法を調べたので備忘録として記載します。

1. ファイル→ファイル/プロジェクトの新規作成→プロジェクトのインポートでGit Repository Cloneを選択
enter image description here

2. リポジトリのURL(以下のようなやつ)をコピーしてクローンURLにコピー
enter image description here

3. ブランチを選択するために以下の赤マルをクリック。

enter image description here

4. パスを指定して次へ
5. Bitbucketのpasswordを入力

2015年3月29日日曜日

RaspberryPIでgitを使ってみる。

RaspberryPIでgitを使ってみる。

1.ユーザー名、メールアドレスの設定

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

2.SSHの鍵の設定

$ 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 same passphrase again: ← もう一度パスフレーズを入力します
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」の内容を
githubのpersonal settingの「SSH Public Keys」に登録する

3.SSHで接続してみる。

$ ssh -l git -i ~/.ssh/github_id_rsa github.com
:
:
Enter passphrase for key '/home/pi/.ssh/id_rsa : さっきのパスフレーズ
:
Connection to github.com closed.
$ vi ~/.ssh/config
Host github.com
 HostName      github.com
 IdentityFile  ~/.ssh/github_id_rsa
 User          git
$ ssh github.com

4.リポジトリからクローンする。
 すでにホームページでリポジトリは作ってあったので、クローンをしてファイルをダウンロードする。

$ git clone リポジトリのurl 

githubと同じフォルダができ、ファイルがダウンロードされる。別のフォルダ(AAA)にダウンロードしたい場合は以下とする。

$ git clone リポジトリのurl AAA

5.新しいファイルをリポジトリに追加

$ git add filename
$ git add directoryname

6.変更したファイルをローカルリポジトリにコミット

$ git commit -m 'something changed'

$ git commit -am “-aオプションを付けるとaddとcommitを一緒にできる”

7.ローカルリポジトリの変更をリモートリポジトリに反映

$ git push
Username for 'https://github.com' : xxx
Password for 'https://xxxxx : yyy

まだよくgitの使い方を理解できていないですが、変更内容をgithubに登録できました。

参考
Ubuntuでgithubを使う
ターミナルからgithubのリポジトリにアクセスする設定(sshの設定)
いまさら聞けないgitの使い方
githubに既にあるプロジェクトからcloneして編集してpushする手順