「Gitでよくやること」の版間の差分

提供: オレッジベース
移動先: 案内検索
(pull)
(clone)
7行目: 7行目:
  
 
=== clone ===
 
=== clone ===
 +
==== とりあえずclone ====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ git clone <REPOSITORY_PATH>
 
$ git clone <REPOSITORY_PATH>
 +
</syntaxhighlight>
 +
==== ディレクトリ指定 ====
 +
<syntaxhighlight lang="bash">
 +
$ git clone <REPOSITORY_PATH> <DIR>
 
</syntaxhighlight>
 
</syntaxhighlight>
  

2019年8月16日 (金) 10:08時点における版

リポジトリの作成

$ mkdir <DIR>
$ cd <DIR>
$ git init --bare --shared

clone

とりあえずclone

$ git clone <REPOSITORY_PATH>

ディレクトリ指定

$ git clone <REPOSITORY_PATH> <DIR>

fetch

とりあえずfetch

$ git fetch

remoteで削除されたブランチをローカルでも削除

$ git fetch --prune

pull

とりあえずpull

$ git pull

remoteで削除されたブランチをローカルでも削除

$ git pull --prune

変更の確認

$ git status

add

とりあえず全部

$ git add -A

新規作成 or 変更されたもの

$ git add .

変更があったもののみ

$ git add -u

commit

$ git commit -m "<MESSAGE>"

push

$ git push <REMOTE> <BRANCH_NAME>

merge

$ git merge <BRANCH_NAME>

branch確認

$ git branch

or

$ git branch -a

checkout

特定のコミットをcheckout

$ git checkout <COMMIT_ID>

ブランチ切り替え

$ git checkout <BRANCH_NAME>

新しくブランチを持ってくる

$ git checkout -b <BRANCH_NAME> <REMOTE>/<BRANCH_NAME>

e.g

$ git checkout -b develop origen/develop

checkoutできないとき

エラー内容

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/remote-name' which can not be resolved as commit?

こうする

$ git remote show <REMOTE>
$ git remote update
$ git fetch
$ git checkout -b <BRANCH_NAME> <REMOTE>/<BRANCH_NAME>

stash

とりあえず面倒なとき

$ git stash

メッセージ付きでstash

$ git stash save "<MESSAGE>"

一覧

$ git stash list

log

1行表示

$ git log --oneline

グラフィカル表示

$ git log --graph

追加/削除行数

$ git log --numstat

変更したファイル

$ git log --name-status

絞り込み

期間(相対値)
$ git log --since="10 days ago" --until="2 days ago"
期間(絶対値)
$ git log --since="2019/03/01" --until="2019/03/03"
件数
$ git log -1
ファイル
$ git log ./dokokanoDIR/nanikanoFILE
$ git log --author='dareka'
コミットログ
$ git log --grep='コメント'
マージコミット
$ git log --merges
マージコミットを除く
$ git log --no-merges

format

$ git log --pretty=format:"[%ad] %h %an : %s"
パラメーター 説明
%H コミットのハッシュ
%h コミットのハッシュ (短縮版)
%T ツリーのハッシュ
%t ツリーのハッシュ (短縮版)
%P 親のハッシュ
%p 親のハッシュ (短縮版)
%an Author の名前
%ae Author のメールアドレス
%ad Author の日付 (-date= オプションに従った形式)
%ar Author の相対日付
%cn Committer の名前
%ce Committer のメールアドレス
%cd Committer の日付
%cr Committer の相対日付
%s 件名
$ git log --oneline --decorate=full --graph --branches --tags --remotes --date=iso --format='%C(yellow)%H%C(reset) %C(magenta)[%ad]%C(reset) %C(cyan)@%an%C(reset) %C(auto)%d%C(reset) %s'

config関連

Author

$ git config --global user.name <NAME>
$ git config --global user.email <EMAIL>

or

$ git config user.name <NAME>
$ git config user.email <EMAIL>

permission変更を無視

$ git config core.filemode false