0
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 2017-11-16

Gitの初心者の方が覚えておくと便利かなと思うコマンド一覧です。

直前のcommitに追加で変更を加えたい

一つ前のcommitに現在の変更を加える

$ git commit --amend

commitしたけど名前が気に入らない

一つ前のcommitの名前を変更する

$ git commit --amend -m "commit name"

1つ以上前のcommitをまとめたい

複数のcommitをまとめる

$ git rebase -i HEAD ~ [commit id]

commit間のdiffをみたい

commit間の変更を見る

$ git diff [commit id] [commit id]

remoteとのdiffをみたい

remoteのbranchとの差を見る

$ git diff HEAD [remote branch]

作業途中だけどremoteからpullしたい

# stashで変更を退避
$ git stash

# 変更がすべて退避されたので、pull
$ git pull [remote branch]

# 退避した変更を適応
$ git stash apply [stash id]

remoteからbranchをcheckoutしたい

$ git checkout -b [branch name] [remote branch]

変更をすべて消し去りたい

一つ前のcommitの状態にもどす

$ git reset --hard HEAD

ある時点のcommitまで戻したい

指定した時点までcommitを戻す

$ git reset [commit id]

commitを消してしまった時

# commitログを確認
$ git reflog

# commitを戻す
$ git reset --hard [commit id]

  

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?