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コマンド一覧 自分用

Posted at

よく使うGitのコマンド一覧をまとめておきます。
個人向けのため、色々説明不足な点ありますがご了承ください。

  • 定期的に更新予定です
  • 間違えている点やより便利な方法があれば、コメントは大歓迎です

基本サイクル

  1. 自分の作業場(ブランチ)を確認・移動する
  2. 作業する
  3. 変更したいものを選ぶ
  4. 変更しまーす & みんなでチェックする
git branch
git checkout ブランチ名
git add ファイル名
git push origin ブランチ名

あるあるシリーズ

リモートの最新をローカルのブランチに反映したい

段階を踏んで反映したい時

git fetch origin main # リモートの状況をとってくるだけで反映前
git branch
git merge oringn/main # 反映する

一括でもできる

git pul origin main

以下、派生系

git merge --no-ff ブランチ名 -m "マージ" # コミット履歴を綺麗できる
git checkout -b 新規ブランチ名 origin/ブランチ名 # ブランチ作成もする

あるブランチの特定のコミットだけ取り込みたい

取り込み元のコミットのIDを検索し、cherry-pickコマンドを使います。

git checkout ブランチ名      # 取り込み元に移動
git log --oneline           # 一行表示すると見やすい
git checkout ブランチ名      # 取り込み先に移動
git cherry-pick "hash-ID"

コミットせずに作業内容を移したい

stashコマンドで作業内容を一時退避できます。
作業中を残しつつ、作業前の状態で動作確認したい時にも使えます。
stashはスタックに積まれます。

git stash -m "作業名"
git checkout ブランチ名
git stash apply

やっちまったけど安心シリーズ

ブランチ名を修正する

最初はおおさっぱに命名してしまい、作業を進めていくうちに作業内容と命名のずれが気になってしまった時など。
ブランチ自体を新規作成することになります。

git branch -m 新ブランチ名

直前のコミットを取り消したいけど、変更内容をなくしたいない

タイポなど微妙なミスに気付いた時。

git reset --soft HEAD~1

Gitについて考える

なんで構成管理するの?

  • 差分がわかる
  • 作業を分割できる
    • ここポイントで前に進んでいる感も出るし、レビューする人も少ない方が(脳が)楽
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?