LoginSignup
0
1

More than 1 year has passed since last update.

Git CheatSheet

Last updated at Posted at 2022-09-18

はじめに

忘れがちなgitコマンドの備忘録です。
都度、メモしていこうかと思います。
誰かのお役に立てれば幸いです。

コマンド

リモートブランチ一覧を表示

git branch -r

リモートブランチをフェッチ

git checkout -b develop origin/develop

ブランチを新規作成して切り替える

git switch -c ブランチ名

編集内容を取り消す

# ステージングエリアから下ろす
git restore --staged ファイル名
# ワーキングツリーの変更を直前のコミットまで戻す
git restore ファイル名

未コミットの変更をすべて破棄する。

# 追跡されているファイルはすべて編集前の状態 (HEAD)に戻る。
git reset --hard

直前のコミットに含め忘れた変更を追加

git commit --amend
# コミットメッセージを変更しない場合は以下
git commit --amend --no-edit

マージしていないブランチを表示

git branch --no-merged

ローカルからリモートのブランチを削除

git push --delete <branch>

リモートで削除されたブランチのローカル参照を削除する

git fetch --prune

巨大なリポジトリを高速でクローンする

# 最新の指定コミット分を取得
git clone --depth=コミット数

コンフリクト時に片方を適用する

# 今いるブランチの変更を適用する
git checkout --ours ファイル名
# マージ先のブランチの変更を適用する
git checkout --theirs ファイル名

別のブランチのファイルを参照する

git show ブランチ名:ファイル名

シンプルなログを見る

git shortlog

ワーキングツリー/ステージングエリア/レポジトリ/リモートレポジトリ

スクリーンショット 2022-09-19 1.21.44.png

参考

Git コマンドリファレンス(日本語版):
https://tracpath.com/docs/

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