gitのコマンド忘れやすいのでメモ
自由に使ってください。
Gitの作業ディレクトリ作成
$ git init
Gitの登録
$ git config --global user.name "{Username}"
$ git config --global user.email {yourmail@example.com}
Proxyは以下のコマンド
$ git config --global http.proxy http://{id}:{pass}@{example.proxy}:8080
$ git config --global https.proxy http://{id}:{pass}@{example.proxy}:8080
もしくはエディタで編集(こっちの方が楽かも)
コマンドから編集する場合(vimを指定)
$ git config --global core.editor 'vim -c "set fenc=utf-8"'
次回からは
$ git config --global -e
直接変更する場合は
$ vi ~/.gitconfig
[user]
name = {UserName}
email = {yourmail@example.com}
[http]
proxy = http://{id}:{pass}@{example.proxy}:8080
[https]
proxy = http://{id}:{pass}@{example.proxy}:8080
[core]
editor = vim -c \"set fenc=utf-8\"
よく使うモノ
AddとCommit
$ git commit -am "commit comment!"
オプション | 意味 |
---|---|
-a | 既存ファイルをaddする |
-m | コメントを残す |
※新しいファイルを作成した時は、commitのオプションaが効かないので
commitの前に$ git add .
する必要がある。
Log
gitのlogはバージョンを行ったり来たりする際に
大事なIDやコメントを確認するため頻繁に使用する
$ git log
おすすめは、ログの一行表示
$ git log --oneline
Checkout
gitのceckoutは、古いバージョンに戻ってファイルの内容を確認したり
元の場所に戻ったりできる。
1. 戻りたいidを確認
$ git log
$ git log
commit f7a7cbf614862d468f7afdad4451c91e07911fae
Author: {user} <yourmail@example.com>
Date: Tue Jul 17 09:58:52 2018 +0900
IDは一意に決まればいいので、他のIDとかぶっていなければ
先頭から5つくらいの数字で良い
2. checkoutで戻る
例として以下のidのように5つの数値のidで戻りたい場所を選択
$ git checkout f7a7c
3. checkoutで元のバージョンに戻る
$ git checkout master
Remote
gitのremoteはリモート用のディレクトリが必要
今回はローカル環境のためurlの代わりにdirectoryを使用した{dir}で示す
コマンド | 意味 |
---|---|
$ git init --bare --share | 違うPCからも共有リポジトリのディレクトリ作成 |
$ git clone {dir} {作成するディレクトリ名} | $ git init --bare --shareで作成したディレクトリを指定してその作業ディレクトリを作成 |
$ git pull origin master | 一度クローンで作成したディレクトリからリポジトリを更新する際に使用する |
$ git push origin master | 作業ディレクトリから共有リポジトリのディレクトリにリポジトリをpushする |
pushはcommitまでされたディレクトリ構成を取り扱うので
作業ディレクトリは、pushする前に最新状態にアップデート($ git commit -am "new commit"
)をする必要がある。