LoginSignup
1
1

More than 5 years have passed since last update.

Git コマンド

Last updated at Posted at 2017-01-16

Gitコマンドのメモ

コミット系

全てコミット(追跡してないファイルがある場合はAddしろって言われる)

$ git commit -am "commit comment"

前のコミットに追加する。(前のコミットがプッシュされている場合にはしない)

git commit --amend -m "commit comment"

空コミット

git commit --allow-empty -m "first commit"

ログ出力

樹形図付き、1列コミットコメントでログを出力

$ git log --oneline --graph

logを一列で表示

git log --pretty=oneline

差分確認

2つのブランチの差分を表示(masterとdevelopの差分を表示)

git diff master develop

ステージングしてあるファイルの差分を見る

git diff --staged

index.htmlの編集履歴を1列毎に確認出来る

git blame index.html --date short

コミット取り消し、削除

追跡をやめる(-rは再帰的。この場合ファイルも消える)

git rm -r target.file

追跡をやめるがファイルは残す場合(-rは再帰的。この場合ファイルも消える)

git rm -r --cached target.file

1つ前のコミットと編集を全て取消(プッシュしてあるコミットにはしない)

git reset --hard HEAD^

2つ前のコミットを取り消すが、編集内容は保持つまりステージングしてある状態(プッシュしてあるコミットにはしない)

git reset --soft HEAD^^

Gitコマンドのカスタム(エイリアス)

mylogというコマンドで""内が実行されるようになる。(デフォルトコマンドは書き換え不可能)

git config --global alias.mylog "log --pretty=format:'%h %s [%an]' --graph"

stというコマンドでstatusが実行される。

git config --global alias.st status
1
1
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
1
1