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コマンドメモ

0
Posted at

はじめに

駆け出しの頃から記録していた個人的なgitコマンドの簡易メモなので、間違っている表現などあるかもしれません。
本記事で紹介するgitコマンドを知っておくと、実務でgit操作に困ることは少なくなると思います。

具体例

  • ブランチの作成とチェックアウト
git switch -c ブランチ名
  • ブランチの切り替え
git switch ブランチ名
  • 変更をまとめてaddする
git add .
  • メッセージを指定してコミットする
git commit -m メッセージ
  • プッシュ
git push origin ブランチ名
  • マージ(作業ブランチにmainブランチを取り込む例)
git switch 作業ブランチ名
git merge main
  • リベース(作業ブランチにmainブランチを取り込む例)
git switch 作業ブランチ名
git rebase main

# pushする場合は
git push --force-with-lease origin 作業ブランチ名
  • ブランチ削除
git branch -d ブランチ名

# 強制削除したいなら
git branch -D ブランチ名
  • コミットログを見る(10行分を見る例)
git log --oneline -10
  • 既存ファイルの変更内容を確認
git diff
  • リモートブランチをローカルに持ってくる
git fetch origin リモートブランチ名
git switch リモートブランチ名
  • 全てスタッシュ
git stash push -u -m "メッセージ"
  • 指定したファイルだけをスタッシュ
git stash push -- ファイルのpath
  • スタッシュリスト確認
git stash list
  • スタッシュを戻す(リスト確認でstash@{0}の部分をチェック)
git stash apply stash@{0}
  • スタッシュを消す(リスト確認でstash@{0}の部分をチェック)
git stash drop stash@{0}
  • Push前に直前のコミットをなかったことに
# addされた状態へ
git reset --soft HEAD^
  • Push済みな直前のコミットメッセージを変更する
git commit --amend -m コミットメッセージ
git push --force-with-lease origin 作業ブランチ名
  • ブランチ名の変更
git branch -m 古いブランチ名 新しいブランチ名
  • 現在のブランチ名の変更
git branch -m 新しいブランチ名
  • 作業ブランチの派生元のブランチを変更
git rebase --onto どこへ どこから どのブランチを

# 既にGitHubでプルリクエストを作成済みな場合は、プルリクエストのマージ先も編集から変更した方がいいこともある
  • gitの履歴を引き継いでファイル移動する
git mv 移動前のパス 移動先のパス

# 以下で履歴を確認できる
git log --follow パス
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?