LoginSignup
2
0

More than 5 years have passed since last update.

git よく使うコマンド一覧

Last updated at Posted at 2018-11-17

目次

・clone
・add
・commit
・push
・log
・pull
・checkout
・fetch
・merge
・cherry-pick

clone

# 1. リポジトリをコピー
git clone [repository PATH]

add

# 1. ファイルやディレクトリをインデックスに追加
git add [filename]

# 2. 全ての変更を含むワークツリーの内容をインデックスに追加
git add -A
or
git add --all

# 3. 以前コミットしたことがあるファイルだけインデックスに追加
git add -u

commit

# 1. インデックスに追加されたファイルをコミットする
git commit

# 2. コミットメッセージを同時に指定
git commit -m "[comment]"

# 3. 変更されたファイル(新規を除く)をインデックスに追加し、コミットする
git commit -a

# 4. 直前のコミットを修正する
git commit --amend

push

# 1. リモートリポジトリに変更を書き込む
git push [remote] [branch]

# 2. リモートリポジトリに全てのタグをアップロード
git push push [remote] --tags

# 3. リモートリポジトリに指定したタグをアップロード
git push [remote] [tagname]

# 4. 指定したブランチ、もしくはタグをリモートリポジトリから削除
git push [remote] :[branch or tagname]

log

# 1. コミットログを参照する
git log

# 2. コミットログの先頭7文字のコミットIDを表示する
git log --oneline

# 3. コミットログのHEADの位置を明示する
git log --decorate

# 4. コミットログを縦グラフで表示する
git log --graph

# 5. 指定した文字がコミットログに含まれるコミットを表示する
git log --grep "検索文字"

pull

# 1. リモートリポジトリの変更を取り込む
git pull [remote repository PATH] [branch]

checkout

# 1. ブランチを変更
git checkout [branch]

# 2. コミットされた過去のリポジトリを復元
git checkout [commit id]

# 3. マージでコンフリクトしたときに情報を指定してファイル内容を採用する
git checkout --ours [filename]

# 4. マージでコンフリクトしたときに下方を修正してファイル内容を採用する
git checkout --theirs [filename]

fetch

# 1. リモートリポジトリの最新情報を追加する
git fetch [remote repository]

# 2. リモートリポジトリの削除情報をローカルに更新する
git fetch --prune

merge

# 1. 現在のブランチに他のブランチをマージする
git merge [input_branch]

#現在:master 取込む:dev
#masterにdevのファイルが取り込まれる
git merge dev

cherry-pick

# 1. 特定のコミットだけマージ
git cherry-pick [commit id]

git cherry-pick ed3eea08d74d5c458b670f6175bbc0b4f77c1308
2
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
2
0