LoginSignup
0
0

More than 5 years have passed since last update.

よく使う Git イディオムまとめ

Posted at

はじめに

開発をしていて使用することの多い Git のイディオムをまとめました。

この他に、Learn Git Branching というサイトで課題をこなしていくと、ブランチの概念がよく理解できます。

イディオム

すべての変更をステージする

$ git add .

すべての変更をステージしてコミットする(1行コメントも入れる)

$ git commit -am "<comment>"

ログを見る(差分付き)

$ git log -p

ログを見る(変更したファイルのリスト付き)

$ git log --stat

$ git log -p の結果が長すぎるときに便利。

作業ディレクトリの差分を見る

$ git diff

ステージングエリアの差分を見る

$ git diff --cached

変更したファイルを元に戻す

$ git co -- <file>

直近のコミットに現在のステージングエリアの変更を遡及的に加える(コメントも修正する)

$ git commit --amend

した後に、コメントを入力する。

作業ディレクトリとステージングエリアの変更をすべて取り消す

$ git reset --hard HEAD

ひとつ前のコミットに戻る

$ git reset --hard HEAD^

master ブランチにプッシュする

$ git push

master 以外のブランチにプッシュする

$ git push origin <branch_name>

他のブランチを現在のブランチにマージして当該他のブランチを削除する

$ git branch`

* <current>
  <another>
$ git merge <another>

した後に、

$ git branch -d <another>

現在のブランチを他のブランチにリベースする

$ git branch

* <current>
  <another>
$ git rebase <another>

以上。

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