#topicpath();
/////////////////////////////////////////////////////////////////////////////////
#contents();

/////////////////////////////////////////////////////////////////////////////////
* Links [#s804db5e]
** Git について [#m5bd67c0]
- [[Gitを使いこなすための20のコマンド>http://sourceforge.jp/magazine/09/03/16/0831212]]
- [[サルでもわかるGit入門>http://www.backlog.jp/git-guide/]]
- [[もっと早く知りたかった! Gitが鬼のようにわかるスライド厳選7選>http://www.find-job.net/startup/7-git-slides]]
- [[Git の基礎勉強 ~ Git によるバージョン管理>http://tracpath.com/bootcamp/learning_git_firststep.html]]
- [[Gitによるバージョン管理入門 for windows>http://www.plowman.co.jp/school/Git/Git.html]]

** Downloads [#xb3ff64e]
- [[Git 配布元>http://git-scm.com/]]



/////////////////////////////////////////////////////////////////////////////////
* 使い方 [#qe3c4374]
//===============================================================================
** 新規リポジトリ作成 [#m16a4953]
+ 空リポジトリの作成
 $ mkdir hoge.git         # bare repository 用の空ディレクトリを作成
 $ cd hoge
 $ git init --bare --shared=true   # bare repository として初期化。管理ファイル群が生成される。共有にするには --shared=true にする
+ 作業用リポジトリの作成
 $ cd ..
 $ git clone hoge          # hoge.git から hoge という名前で bare ではないリポジトリとして複製する
+ 作業用リポジトリでファイルを登録
 $ cd hoge
 /* 何かしらの方法で新しいファイル fuga を置く */
 $ git add fuga           # ファイル "fuga" が登録対象になる(まだ登録されていない)
 $ git commit             # 前の git add で指定されたファイルが登録される 



//===============================================================================
** git commit : 登録済みのファイルに変更が加えられた場合 [#s57eee2a]
- 再び add, commit を行う
 $ git add <変更を加えたファイル>
 $ git commit

//===============================================================================
** git revert : commit を取り消す [#ud26aece]
- 「取り消す」とはいっても、 commit の痕跡自体は消せるわけではなく、単に元に戻すための commit ができますよ、という機能。
+ まず、git log で対象 commit の hash を確認
 $ git log
 commit bdf1da8aecdfbe5a83ce93e78e2ad8a241b1530b
 Author: hogehoge <hogehoge@fuga.com>
 Date:   Mon May 4 13:33:13 2015 +0900
 
     fix build break for System
 
 commit 1072326e20c9dd482d5e1db46419b0412317d693
 Author: hogehoge <hogehoge@fuga.com>
 Date:   Mon May 4 13:12:33 2015 +0900
 
     delete Makefile.bak
 
 ...
+ 対象を確認したら、 hash を指定して revert する
 $ git revert bdf1da8aecdfbe5a83ce93e78e2ad8a241b1530b
-- 即座に commit log 編集画面になる。

//===============================================================================
** git reset: 変更をなかったことにする [#c43362c5]
 $ git reset [commit-hash]
- [commit-hash] を取り消す
- [commit-hash] を指定しなかった場合、HEAD が指定されたとみなされる
- [commit-hash] には以下が使用出来る:
-- HEAD: 最新
-- <commi-hash>^ or <commit-hash>^1 : <commit-hash> の1個前
-- <commi-hash>^^ or <commit-hash>^2 : <commit-hash> の2個前
- 但し、remote へ push 済みの commit に対して reset を行なっても、 reset を remote には push 出来ないようなので注意が必要。

//===============================================================================
** branch の名前 [#l57722cb]
*** リポジトリの現在の branch 名を表示 [#g036243a]
 $ git branch
 * work

*** branch 名を変更する [#x3a53663]
- デフォルトでは "master" になっているが、用途に合わせて任意の名前を付けることが出来る。
- 変更するリポジトリ内にて、以下のようにする:

 $ git branch -m <元の名前> <新しい名前>



//===============================================================================
** リポジトリの変更を他のリポジトリに反映する [#p5019a98]
 $ git push <反映先> <反映元>


//===============================================================================
** branch 操作 [#y0bb3352]
*** branch 作成 [#t63da454]
- 例として新しく作成する branch の名前を "work1" とする
- (例えば masterのディレクトリ内で)次の操作を行う
 $ git checkout work1
*** branch 切り替え [#d2701e8e]
- 切り替えの時も git branch を実行する。操作が成功すれば以下のようにブランチが切り替わったことを通知するメッセージが表示される
 $ git checkout work1
 Switched to branch 'work1'
-- この時、元の branch と work1 の間に差分があれば、現在のディレクトリの内容も work1 の最新の状態に切り替わる
-- 但し、元の branch で修正して commit さてていない変更点がある場合、その差分はそのまま残される。つまりその変更点が存在する状態で work1 に切り替わっている

*** 不要になった branch の削除 [#wdab01db]
- 不要になった branch work1 を削除するには、
 $ git branch -d work1

//===============================================================================
** 他の branch に commit を反映する [#v07f7442]
 $ git merge <反映先 branch>


//===============================================================================
** tag  [#tag]
- 現在のリポジトリの最新に対してタグ <tag-name> を付ける場合
 $ git tag <tag-name>
- 特定の commit <commit-hash> に tag  を付ける場合
 $ git tag <tag-name> <commit-hash>
- 既に親 repository に push してしまった commit に後から tag を打っても、親 repository には反映できない。~
→ git push --tags を使う
 $ git push --tags # 全ての tag 情報を push する
- tag の削除
 $ git tag -d <tag-name>

//===============================================================================
** commit されていない変更点の確認 [#v1309767]
- 全ての差分を表示
 $ git diff
- 変更された管理対象のファイルの一覧を見る
 $ git clean [-n]
-- -n の代わりに -f を付けると、全ての変更を revert する
- 管理対象外のファイルも含め、変更ファイルの一覧を見る
 $ git status


/////////////////////////////////////////////////////////////////////////////////
* [[Subversion>VersionCtl/Subversion]] とのコマンド対比 [#q65add11]
|~Git |~Subversion |~Description |
|git init |svnadmin create |リポジトリ作成 |
|git clone |svn checkout |リポジトリのコピー |
|git add <file> |svn add <file> |ファイルの追加 |
|git add <file>; git commit |svn commit [file] |ファイルの更新をリポジトリに反映 |
|git rm <file> |svn rm <file> |ファイルの削除(別途、要 commit) |
|git status |svn status | |
|git log [file] |svn log [file] |ログを表示する |
|git blame <file> |svn blame <file> |<file> の各行がいつ誰によって変更されたかを表示する |
|git checkout <branch> |svn switch <branch> | |
|git merge <branch> |svn merge <branch> | |
|git checkout <file> |svn revert <file> |ファイルに対して行った(リポジトリに未反映の)変更を元に戻す |
|git clean -f |svn revert [dir] |~|
|git pull <remote> <local> | svn up[date] |<remote> の最新状態を <local> に merge する |


/////////////////////////////////////////////////////////////////////////////////
* tools [#w65817d7]
//===============================================================================
** git-sh [#y50d6b1c]
- git コマンドを打つときに "git" と入力するのを省略できるようになる
- 現在のリポジトリと branch の名前がプロンプトに表示されるため、 branch コマンドを打つ必要もなくなる。



/////////////////////////////////////////////////////////////////////////////////
* tools on emacsen[#tools]
//===============================================================================
** magit [#magit]
- リポジトリ: https://github.com/magit/magit.git
- debian の場合、 magit パッケージを install すると、即使えるようになる。
- psvn.el のように、 "e" (※注: "E" ではない)で差分を ediff で閲覧・ merge 出来る

//===============================================================================
** git-gutter+ [#git-gutter-plus]
- リポジトリ: https://github.com/nonsequitur/git-gutter-plus.git
- [[git-gutter>#git-gutter]] よりも高速らしい

//===============================================================================
** git-gutter [#git-gutter]
- [[git-gutter.el>http://emacs-jp.github.io/packages/vcs/git-gutter.html]]


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS