Skip to content

Instantly share code, notes, and snippets.

@maechabin
Last active August 22, 2022 03:02
Show Gist options
  • Save maechabin/4529584 to your computer and use it in GitHub Desktop.
Save maechabin/4529584 to your computer and use it in GitHub Desktop.
ドットインストールの内容まとめ

gitコマンド一覧他

--gitの基本--

1. 作業ディレクトリ 2. ステージングエリア(インデックス) 3. リポジトリ(ローカル、リモート)

--コマンド一覧--

  • git init: 作ったディレクトリをgitで使うための宣言

  • git add: ステージングエリアに上げる

  • git commit: リポジトリに上げる

  • git log: ログを見る

  • git commit -am "---": addとcommitを同時に行う

  • git log --oneline: コンパクトに見る

  • git log -p: 変更された場所を具体的に見る

  • git log --stat: どのファイルが何箇所変更されたか見る

  • git status: 今ファイルがどの状態にあるか確認する(次にやることを教えてくれる)

  • git checkout -- ファイル名: チェックアウトする

  • git diff: ステージングエリアにあげる前 変更箇所を確認する

  • git diff --cached: ステージングエリアにあがってる状態(コミット前) 変更箇所を確認する

  • git add .: 今のディレクトリより下にあるファイルを全部addする

  • git rm / git mv: git上での削除 / 移動

  • .gitignore: gitで管理したくないファイルを登録しておく 適用範囲:ディレクトリ以下

  • git commit -m "(message)": エディタを立ち上げずにコミットする

  • git commit --amend: 直前のコミットを変更 ログを増やしたくないとき

  • git reset 元に戻す

  • git reset --hard HEAD: 直前のバージョンに戻す

  • git reset --hard HEAD^: 直前の1個前に戻す

  • git reset --hard id: idのバージョンに戻す

  • git reset --hard ORIG_HEAD: 前回取り消されたバージョンに戻す

  • git branch: 今あるブランチを確認する

  • git branch (branch name): 新しくブランチを作る *今いるブランチ

  • git checkout (branch name): branch nameのブランチに移動(スイッチ)する

  • git merge (branch name): 今いるブランチにbranch nameのブランチをマージする

  • git branch -d (branch name): branch nameのブランチを削除する

コンフリクトの発生

コンフリクトの解決

git tag 

  • git tag (tag name): 直前のcommitにタグをつける
  • git show (tag name): 指定したタグのcommitを確認する
  • git tag (tag name) (commit id): 任意のIDのcommitにタグをつける
  • git tag -d (tag name): タグを削除する

--エイリアス例--

  • git config --global alias.co checkout: checkoutにcoというエイリアスをつける
  • git config --global alias.st status
  • git config --global alias.br branch
  • git config --global alias.ci commit
  • git config -l: 登録したエイリアスを確認する

共有リポジトリ(hogehoge.git)(リモートサーバーなどに置く)

  • git init --bare: 作ったディレクトリをgitで使うための宣言(共有リポジトリの場合)

  • git remote add origin (repos location): 別のリポジトリを追加

  • git remote rm: 別のリポジトリを削除する

  • git push origin master: 共有リポジトリoriginに向かってmasterの内容をつっこむ

  • git clone ~/ourweb.git/ myweb2: 共有リポジトリourweb.gitの中身をmyweb2の中身にする

  • git push

  • git pull: 共有リポジトリの内容を自分のところへマージする

  • git pull/push

  • コンフリクトの解決

-- 参考書(日本語)

『pro-git』

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment