6. リポジトリの作成
git init
$ cd HelloApp
$ git init
local repository
6
7. リポジトリへの登録
git add, git commit
working tree index local repository
hello.c hello.c hello.c
Makefile Makefile Makefile
git add git commit
git commit -m "Message"
7
8. 管理外のファイルを無視する
.gitignore
working tree index local repository
hello.c hello.c hello.c
Makefile Makefile Makefile
hello.o
hello
.gitignore
hello.o
hello
8
9. 差分を出力する
git diff
working tree index local repository
hello.c hello.c hello.c
Makefile Makefile Makefile
hello.o git diff git diff HEAD
hello
HEADは最新コミット
.gitignore .gitignore .gitignore
9
11. コミットをなかったことにする
git reset
HEAD^^^ HEAD^^ HEAD^ HEAD
38a123~ 4a8931~ 13ea90~ 124b34~
A B C D 最新コミット
git reset --hard HEAD^^
HEAD^ HEAD
38a123~ 4a8931~
A B 最新コミット
11
12. コミットをなかったことにする
git reset
working tree index local repository
hello.c hello.c hello.c
git reset --soft HEAD^
ワーキングツリー
は影響無し
foo.c foo.c foo.c
git reset --mixed HEAD^
12
13. コミットを前の状態に戻す
git revert
HEAD^^^ HEAD^^ HEAD^ HEAD
38a123~ 4a8931~ 13ea90~ 124b34~
A B C D 最新コミット
$ git revert HEAD^^
$ git commit -m "E" Bのコミット
状態で最新
「変更」の履歴が残る
38a123~ 4a8931~ 13ea90~ 124b34~ 342b34~
A B C D E
13
14. ブランチを利用する
git branch, git checkout
A B masterブランチ
C develブランチ
$ git branch devel master 「branch」…ブランチの作成
$ git checkout devel
: 「checkout」…ブランチの切替え
$ git commit -am "C"
14
15. ブランチのマージ
git merge
master
A B E ブランチ
マージ
C D
devel
ブランチ
$ git checkout master
$ git merge devel
15
16. ブランチのマージ
git merge
master
A B D F ブランチ
マージ
C E
devel
ブランチ
$ git checkout master
$ git merge devel
<コンフリクトが起こる可能性有り>
16
17. ブランチのリベース
git rebase
master
A B D ブランチ
devel
C E ブランチ
$ git checkout devel
$ git rebase master
A B D masterブランチに追従
devel
C' E' ブランチ
17