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?

gitコマンドメモ

Last updated at Posted at 2015-02-09

よく使うものはエイリアスに登録すると便利です。
~/.zshrc や ~/.bashrc にこんな感じで入れてます。

alias gad="git add -p"
alias gp="git pull"
alias glmy="git log --author=yulily"

■ git add

git add -p
変更箇所を確認しながらインデックスへ追加。

■ git branch

git branch
ローカルにあるブランチの一覧を表示する。
git branch -r
リモートにあるブランチの一覧を表示する。
git branch -a
ローカルとリモートのブランチを表示する。
git branch -d
ローカルブランチを削除する。 ( マージされていないとできない
-d を -D にするとマージされていなくても削除できる。
リモートブランチも削除する場合。
git push --delete origin [ブランチ名]
または
git push origin :[ブランチ名]
2つ目はこちらに何故そうなるのか解説がありますmm

■ git-checkout

git checkout -b newbranch([派生ブランチ名])
現在のブランチから派生ブランチを作成し、派生ブランチに切り替える。

■ git cherry-pick

git cherry-pick 123hoge(HASH)
別ブランチのコミットを適用させる。
git cherry-pick -n 123hoge(HASH)
コミットせず該当コミットを取り込む。

■ git fetch

リモートリポジトリから最新情報をローカルへ持ってくる。

■ git stash

コミット前の作業を一時退去。
別のブランチで作業する必要がでた場合などに使用。
git stash save
現在の作業ツリーを保存。
git stash save "message"
メモも付ける事ができる。
git stash list
スタックに格納した一覧を表示 。
git stash pop
最後に格納したスタック内容を現在のブランチに適用。
適用後スタックから削除。
git stash pop stash@{[stash番号]}
指定した stash番号 の内容を現在のブランチに適用する。
[stash番号]は、listした時に表示されるのでそれを入れる。
git stash apply
適用後スタックから削除しない。
git stash drop
スタックから削除する。
git stash clear
スタックに保存されている内容を全て削除。
git stash show stash@{[stash番号]}
指定したスタック内容と親コミットのdiffstatを表示。
-pを付けると差分表示。
git stash branch new-branch stash@{[stash番号]}
最後のスタックから新しいブランチを作成。
git stash show -v
保存されている修正内容の詳細を表示。
git checkout stash@{[stashの番号]} [ファイル名]
指定した stash番号 の特定のファイルだけワークツリーに戻す。
git stash -p
使ったこと無いが、指定したファイルだけ stash に入れられるようです。
git add -p のように使えるらしいです。

■ git revert

git revert 123hoge(HASH)
指定したコミットの変更分を元に戻すための新しいコミットを追加する。
指定したコミットのみを元に戻すコマンド (打ち消し)。
そのコミットの後に行われたすべてのコミットを元に戻して過去のある状態に戻すコマンド (取り消し) ではない。
打ち消し -> revert
取り消し -> reset

■ git log

git log author=yulily
特定ユーザのコミット履歴閲覧。

■ git merge

git merge [ブランチ名]
指定したブランチ名の変更を現在ブランチに合流させる。
git merge --squash
指定したブランチのコミット全てをまとめたコミットが追加される

■ git rebase

コミットの移動・修正
git rebase -i 123hoge(HASH)
HEAD から指定したコミットハッシュまでを対象に、必要なコミットを取捨選択し統合、ハッシュではなくブランチ名でもできる。
ここでコミットのコメント修正したり、順序入れ替えができる。
git rebase --onto [ブランチ名1] [ブランチ名2] [ブランチ名3(省略可)]
ブランチ名2 からブランチ名3 の内容を、ブランチ名1 の上に乗せる。ブランチ名3は省略された場合、現在いるブランチになる。

■ git diff

git diff origin/master..master --name-only
ローカル master とリモート master ファイル名のみ差分抽出。

■ git reflog

commit 以外のコマンドの履歴が確認できる。

■ git update-index

git update-index --skip-worktree [file_name]
git管理下にあるファイルを無視する。

git update-index --no-skip-worktree [file_name]
無視した設定を取り消す。

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?