LoginSignup
0
0

More than 1 year has passed since last update.

コミット、コミット中止、コミットメッセージとは

Posted at

現在の状態を一つのコミットとしてリポジトリに入れる

ファイルをステージする

コミットするときは作業ツリーの状態をステージに作る。
(変更内容を)
ステージされたらコミットする。前回は

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に変更する。

出典 https://linux.keicode.com/prog/git-staging.php

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0