1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitコマンドメモ

Last updated at Posted at 2019-10-07

git

いつやるの?Git入門

gitのメリット

  • コミット対象を自由に選べる
  • コミット内容を後から修正できる。
  • ほとんどの作業をローカルで完結できる
  • ブランチやタグ操作が高速
  • 効率的にリポジトリ内のデータを保持

最低限のコマンド

ローカルからリモートへ
git add <filepattern>
git commit -m <msg>
git push <remote> <refspec>
branch作成
git branch [<old>] <new>
git checkout <branch>
git checkout -b <new> <old>
リモートからローカルへ
git clone <url>
git fetch
git pull <remote> <refspec>

ローカル環境で使う基本的なGitコマンド

commitするまで編集は記録されず、pushしなければリモートリポジトリに反映されない

git init

gitの管理を開始する

git add <filepattern>

リポジトリに追加したい対象を指定する

git commit -m <msg>

更新内容にコメントをつけてリポジトリに登録する

リモートリポジトリにpushする内容を決定し、コミットIDが発行される。コミット毎に内容が記録されていく。

git rm <file>

ファイルを削除する

git rm -r <directory>

ディレクトリを削除する

git reset HEAD <file>

ステージングエリアをGitリポジトリ(コミットした)の状態に戻す
HEADについて
HEADの指定方法

  • チルダ~ 人世代前のコミットを指定
  • キャレット^ 複数の親がいる時の親コミットを指定できる

git checkout --<file>

ワークツリーをステージングエリアの状態(addした状態)に戻す

git reset --<mode> <commit>

データ領域を指定commitの状態に戻す
git resetオプション

git status

ツリーの状態を確認する

git log

コミットログを見る

git diff

ワーキングツリーとインデックスの差分を表示する

git diff --cached
HEADとインデックスの差分を表示する

リモート環境と関連して使う基本コマンド

git branch [<old>] <new>

branchを作成する

注意:HEAD(作業中のブランチ)は変わらない

git checkout <branch>

HEAD(作業ブランチ)を変更する

git checkout -b old

branchを作成し、作成したブランチを作業ブランチに切り替える

get merge <branch>

現在のブランチに指定ブランチをマージする

git rebase <branch>

現在のブランチを指定ブランチからリベースする

git clone <url>

リモートリポジトリをローカルに複製

git push <remote> <refspec>

リモートリポジトリに変更を送信

git fetch <remote> <refspec>

ローカルブランチをリモートブランチの最新の状態に更新

git pull <remote> <refspec>

ローカルブランチをリモートブランチの最新の状態に更新してマージする

git pull <remote> <refspec> --rebase

ローカルブランチをリモートブランチの最新の状態に更新してリベースする

心がける使い方

  • 基本ローカルで作業
  • push,pullは必要以上に行わない
  • データ領域を意識して作業する

参考-リスペクト

1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?