LoginSignup
0
1

More than 5 years have passed since last update.

Gitのよく利用するコマンド備忘録

Last updated at Posted at 2018-08-25

リモートリポジトリをローカルにコピー

git clone [URL]

ローカルブランチをリモートリポジトリに送信

git push -u origin branch_name

originという名前のリモートリポジトリのbranch_nameブランチに現在のブランチの内容を送信する。

リモートリポジトリからブランチを持ってくる

git checkout -b feature-D origin/feature-D

git checkout -b ローカルブランチの名前 元となるブランチでリモートにあるブランチを新しい名前でローカルに持ってくる。

ローカルリポジトリの状態を確認

git status

ローカルの特定ファイル(test.txt)の変更をステージング

git add test.txt

ローカルの変更を全てステージング

git add .

ステージングしたものをコミット

git commit -m "コミットメッセージ"

ローカルに存在するブランチを確認する

git branch

ローカルとリモート両方に存在するブランチを全て確認する

git branch -a

現在のブランチから新しいブランチを作成しつつ、そのブランチに移動

git checkout -b 新しいブランチ名

リモートブランチをローカルに持ってくる

git branch ブランチ名 origin/ブランチ名

addしてないローカルの変更を取り消す

git checkout .

変更は取り消せるが、新規追加したファイルは削除されないことに注意。

addしたものを取り消し

git reset HEAD .

変更を一時的に退避

git stash

退避したものの一覧を見る

git stash list

//出力
stash@{0}: WIP on ブランチ名: ハッシュ値 コミットメッセージ
stash@{1}: WIP on ブランチ名: ハッシュ値 コミットメッセージ

退避した作業を元に戻す

//stash@{0}の作業を元に戻す
git stash apply stash@{0}

退避した作業を削除する

//stash@{0}を削除する
git stash drop stash@{0}

退避した作業を元に戻し、なおかつstashから削除する

git stash pop stash@{0}

最後にそのファイルを触った人がわかる

git blame ファイルパス

gitのログを一行ごとで見る

git log --oneline

gitのコミット履歴をグラフで見る

git log --graph

現在の変更の差分を見る

git diff

git reset - 変更を取り消し

--hard

削除 残す
コミット
インデックス
ファイルの変更

とりあえず今のコミットを取り消したい時

git reset --hard HEAD~

--soft

削除 残す
コミット インデックス
ファイルの変更

--mixed

オプション指定しない時のデフォルト。

削除 残す
コミット ファイルの変更
インデックス
0
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
0
1