現在の状態を一つのコミットとしてリポジトリに入れる
ファイルをステージする
コミットするときは作業ツリーの状態をステージに作る。
(変更内容を)
ステージされたらコミットする。前回は
git add README
このようにファイル名を指定してステージした。
しかし一つ一つするのはめんどくさい。
なので
作業ツリーから全部のファイルをステージするコマンドがある。
git add -u
ステージ内容をコミットする
git commit
ステージの状態からコミットが作られてリポジトリに入る。
コミットの中止
コミットメッセージの全ての行を消して保存してエディタを終了すると、git commit
は中止と判断してコミットを取りやめてくれる。
思ったこと
コミットメッセージを全て消せば中止し、エディタを終了すると中止になるんだ。
gitでvimを使うんだな。
コミットのハッシュ
コミットを識別するためにIDが使われている。
それに使われているのがハッシュ関数だ。
コミットされた後ハッシュ関数のIDの先頭7桁が表示されている。
Gitは現在のコミット(最新のコミット)をさせるポインタを保持している。
そのポインタをHEAD
という。
次々とコミットをしていくとポインタが先(最新)へ移動することが想像できる。
その流れが家系図のように見える。このような図をコミットグラフ
という。
現在のHEADを子
一つ前(その前のHEAD)を親
という。
また親の親の親を先祖
、子や子の子を子孫
という。
コミットメッセージの書き方
十分な情報を書こう。
わかりにくく書かない。
しかし
エディタを立ち上がらせず1行で済ますのであればこのコマンド
git commit -m 'README ファイルを作成'
演習
1.前説の演習でREADMEファイルをステージした。この状態でコミットしよう。
コミットするには変更箇所がステージにあるのでコミットしたいものをステージする(add)その後はそれをコミットメッセージを添えてコミットする。
ステージの差分を表示させる
git status
HEADが指すコミットと、ステージと、作業ツリーの差を表示させる。
*********@mbp myProject % git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README
三つの差どういうことだ。
HEADとステージの差はcommit前だからわかる。
ステージと作業ツリーの差はステージするのは必ず全部ではないからわかる。
(これもADDされていない。)
HEADと作業ツリーの差どういうことだろう?
つまりまだaddされていないのか。
一応実験的に作業ツリーに新しくファイルを作ってみて確かめてみよう。
***********@mbp myProject % vim hogehoge
iを入力 書き込み
This is a test project.
escを入力 書き込み終了
:wqで内容を保存
**********:@mbp myProject % git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README
Untracked files:
(use "git add <file>..." to include in what will be committed)
hogehoge
hogehogeが書いてあった。
これでステージング前としてファイルも表示される。
hyoudoumasatomo@mbp training % git commit README.md
hint: Waiting for your editor to close the file... error: cannot run rubymine: No such file or directory
error: unable to start editor 'rubymine'
Please supply the message using either -m or -F option.
hint: Waiting for your editor to close the file... error: cannot run rubymine: No such file or directory
error: unable to start editor 'rubymine'
Please supply the message using either -m or -F option.
ファイルが閉じることをエディタが待っています。
rubymineが起動していません。
エディタrubymine
が始まっていない。
-m
か-F
を使うメッセージを指定してください。
思ったこと
rubymineに関係があることしかわからない。
エラーメッセージを検索してみる。
https://t-cr.jp/memo/19717aa46f797c274
を見てみた。
そうすると
**********@mbp training % git config --global -l
user.name=mhyodo
user.email=*************
init.defaultbranch=master
core.excludesfile=/Users/**********/.gitignore_global
core.editor=rubymine
difftool.sourcetree.cmd=*************
difftool.sourcetree.path=
mergetool.sourcetree.cmd=************
mergetool.sourcetree.trustexitcode=true
color.ui=auto
rubymineであっているはず...
と思ったが
**********@mbp training % git config --global -l
user.name=mhyodo
user.email=*************
init.defaultbranch=master
core.excludesfile=/Users/**********/.gitignore_global
core.editor=vim
difftool.sourcetree.cmd=*************
difftool.sourcetree.path=
mergetool.sourcetree.cmd=************
mergetool.sourcetree.trustexitcode=true
color.ui=auto
エディタをvim
に変更する。