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 主なコマンドまとめ

1
Last updated at Posted at 2021-02-25

単なるgitコマンド備忘録。
ちょいちょい追加していきます。

リポジトリを新規作成する

$ git init

ファイルをインデックスに追加する(ステージングする)

$ git add

コミットする

$ git commit

ワークツリーのファイルの状態を確認する

$ git status

コミットのログを確認する

# すべて表示
$ git log

# 一行で表示する
$ git log --oneline

# ファイルの変更差分を表示する
$ git log -p index.html

# 表示するコミット数を制限する
$ git log -n <コミット数>

変更差分を確認する

# git addする前の変更分
$ git diff
$ git diff <ファイル名>

# git addした後の変更分
$ git diff --staged

ワークツリー、gitの記録からファイルごと削除(そもそもファイル自体が不要になった)

$ git rm <ファイル名>
$ git rm -r <ディレクトリ名>

ワークツリーにファイルを残し、gitの記録からのみ消したいとき(パスワードファイルなどgitには上げないけど手元には残したいなど)

$git rm --cached <ファイル名>

ファイルの移動を記録する

$git mv <旧ファイル> <新ファイル>

それは下記と同じ効果である

$mv <旧ファイル> <新ファイル>
$git rm<旧ファイル>
$git add<新ファイル>

ブランチを作成する

$ git branch <ブランチ名>

ブランチの作成だけで、ブランチ切り替えは行いません。

ブランチの一覧を表示する

$ git branch

現在のブランチがどのコミットを指しているか確認

$ git log --oneline --decorate

ブランチを切り替える

$ git checkout <既存ブランチ名>

ブランチの作成と切り替えを同時に行う

$git checkout -b <新ブランチ名>

切り替えると、HRADも切り替えたほうのブランチに移動する

ブランチ名を変更する

$ git branch -m <新ブランチ名>

ブランチを削除する

$ git branch -d <ブランチ名>

変更作業がマージされずに残っている場合は削除されない。

変更履歴をマージする

$ git merge <ブランチ名>
$ git merge <リモート名/ブランチ名>
$ git merge origin/master

origin:GitHub(リモート)を意味する

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