さくらレンタルサーバーでのgit管理

バージョン管理したいフォルダに移動

% git init
% git status
$ git add .  (全てのファイルをインデックスへ追加)
$ git commit -m "2016/12/11 commit"  (コメントは任意)

リモートリポジトリの作成

% mkdir git
% cd git
% ls
% mkdir remote.git
% git init --bare

リモートリポジトリへpush

% git remote add origin ssh://hoge@siriuz.sakura.ne.jp/home/hoge/git/remote.git
% git remote -v
origin  ssh://hoge@siriuz.sakura.ne.jp/home/hoge/git/remote.git (fetch)
origin  ssh://hoge@siriuz.sakura.ne.jp/home/hoge/git/remote.git (push)
% git push origin master:master

ログ

% git log

git diff

% git diff

commit logの閲覧終了:q
git checkout

hidden file you can find
ls -a

git diff
git diff –staged
git diff commit1 commit2

git branch
-git branch
-git branch easy-mode

[vagrant@localhost reflections]$ git branch
* master
[vagrant@localhost reflections]$ git branch easy-mode
[vagrant@localhost reflections]$ git branch
  easy-mode
* master

checkout

[vagrant@localhost reflections]$ git checkout easy-mode
Switched to branch 'easy-mode'
[vagrant@localhost reflections]$ git branch
* easy-mode
  master

git log –graph –oneline

git merge

[vagrant@localhost reflections]$ git merge master easy-mode
Updating d878411..bdd001b
Fast-forward
 asteroids/game.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

remote branchへのpush
git push origin master

diff command

mac os use this command


[vagrant@localhost git]$ diff -u game_new.js game_old.js
--- game_new.js 2016-12-11 08:17:10.604013030 +0900
+++ game_old.js 2016-12-11 08:17:10.605013028 +0900
@@ -4,9 +4,9 @@
 //

 KEY_CODES = {
-  13: 'enter',
   32: 'space',
   37: 'left',
+  38: 'up',
   39: 'right',
   40: 'down',
   70: 'f',
@@ -392,7 +392,7 @@
       this.vel.rot = 0;
     }

-    if (KEY_STATUS.spacr) {
+    if (KEY_STATUS.up) {
       var rad = ((this.rot-90) * Math.PI)/180;
       this.acc.x = 0.5 * Math.cos(rad);
       this.acc.y = 0.5 * Math.sin(rad);
@@ -406,7 +406,7 @@
     if (this.delayBeforeBullet > 0) {
       this.delayBeforeBullet -= delta;
     }
-    if (KEY_STATUS.enter) {
+    if (KEY_STATUS.space) {
       if (this.delayBeforeBullet <= 0) {
         this.delayBeforeBullet = 10;
         for (var i = 0; i < this.bullets.length; i++) {
@@ -919,7 +919,7 @@
     waiting: function () {
       Text.renderText(ipad ? 'Touch Sreen to Start' : 'Press Space to Start', 36, Game.canvasWidth/2 - 270, Game.canvasHeight/2);
       if (KEY_STATUS.space || window.gameStart) {
-        KEY_STATUS.space = false; // hack so we don't move right away
+        KEY_STATUS.space = false; // hack so we don't shoot right away
         window.gameStart = false;
         this.state = 'start';
       }

git基本コマンド

gitはバージョン管理システムです。バージョン管理にはその他にサブバージョンなどありますが、gitの方が一般的でしょう。

git

履歴をデータベースに保存し、環境は、作業ディレクトリ、ステージングエリア(インデックス)、リポジトリの3つがあります。ファイルの修正等は作業ディレクトリで行い、まとめたものをステージングエリアに保存し、それをリポジトリに保存します。リポジトリはローカルとリモートがあります。

gitの初期設定では、名前、アドレス、メッセージをカラーにしたりします。

[vagrant@localhost ~]$ git config --global user.name "name"
[vagrant@localhost ~]$ git config --global user.email "address@mail.com"
[vagrant@localhost ~]$ git config --global color.ui true
[vagrant@localhost ~]$ git config -l
user.name=name
user.email=address@mail.com
color.ui=true

Git コマンド

・ディレクトリを使う宣言
git init
・ファイルをステージングに上げる
git add index.html
・コミット
git commit
・コミットの履歴閲覧
git log
・git logを一行表示
git log --oneline
・git logにコミットの変更箇所を表示
git log -p
・変更したファイル名の表示
git log --stat
・ファイルの状態を確認
git status
・modifiedの状態にあるファイルの変更内容を元に戻す
git checkout -- index.html
・ファイルの変更内容の表示
git diff
git diff --cached (ステージング)
・今のディレクトリより下にあるファイル全てをステージングに上げる
git add .
・gitの管理下にあるファイルの削除
git rm index.html
・gitの管理下に置かないファイルの設定
vi .ignore
 *.log (拡張子が.logのものはgitを含まないという設定)
・commitの際にコメントを一行しか書かない
git commit -m "coment"
・直前コミットの修正
git commit --amend
・直前のコミットにファイルを戻す
git reset --hard HEAD
・直前の更に一つ前に戻す
git reset --hard HEAD^
git reset --hard commit id(7桁以上)
・resetして取り消されたファイルにもどる
git reset --hard ORIG_HEAD
・ブランチの表示
git branch
・ブランチの作成
git branch hoge
・ブランチの移動
git checkout hoge
・元のブランチから別のブランチをマージ
git merge hoge 
・ブランチの削除
git branch -d hoge
・ブランチを作成してチェックアウト
git checkout -b hogehoge
・git mergeのコンフリクトの修正
=>不要なコンフリクトの内容を削除
・コミットにタグを付与
git tag vo.1
・タグを表示
git tag
・コミットの内容を表示
git show
・コミットのタグを表示
git show tag
・任意のコミットにタグを表示
git tag vo.09 id(7桁以上)
・タグの削除
git tag -d vo.1
・エイリアス(短縮名)の設定
git config --global alias.co checkout
・コンフィグの確認
git config -l
・共有リポジトリ
git init --bare
filename.git(ファイル名)
・共有リポジトリに送る
git remote add origin ~/filename.git
・共有リポジトリにpush
git push origin master
・共有リポジトリの中身を任意にファイルにコピー
git clone ~/filename.git hogehogehoge
・リポジトリの変更内容を確認
git pull origin master