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 2024-12-31

前提

以下の記事内の用語を
理解していることを前提としています。

具体的な使用場面をイメージしたい場合は、
以下の記事を参照してください!

開発

ブランチの作成

  • git switch
    指定したブランチに切り替える。

  • git switch -c
    新しいブランチを作成してそのブランチに切り替える。

  • git branch ブランチ名
    新しいブランチを作成するが、切り替えはしない。

ブランチ内での作業

現状確認のコマンド

  • git status
    変更されたファイルの状況やステージングの状態を確認する。

  • git diff
    作業しているブランチとステージングエリアの差分を確認する。

  • git log
    コミット履歴を確認する。

  • git reflog
    ブランチの変更履歴や過去の状態を確認する。(resetなども含む)

  • git branch
    ローカルのブランチ一覧を表示し、現在のブランチを確認する。

途中の作業の退避・適用

  • git stash -u
    一時的に作業内容を退避させる

  • git stash list
    一時的に退避させた作業内容(stash)の一覧を表示する。

  • git stash pop stash@{数字}
    指定したstashを元に戻して適用し、stashリストから削除する。

機能作成に1段階つく

  • git add ファイル名
    指定したファイルをステージングエリアに追加する。

  • git commit -m "コミットメッセージ"
    ステージングエリアの変更をコミットに記録する。

【コミットメッセージの書き方】

目的の機能作成を終えた後

  • git push origin ブランチ名
    ローカルブランチの変更をリモートリポジトリにプッシュする。

ブラウザのGitHubに移動した後

  1. Pull Requestを作成し、変更内容を確認する。
  2. 内容が問題なければMergeする。

ブランチ側で main を統合する

  • git merge main
    現在のブランチに main ブランチの変更を統合する。

  • git rebase main
    以下の記事を参照してください、図解して分かりやすくまとめられています!

リモートリポジトリの内容をローカルに反映

  • git pull origin ブランチ名
    リモートリポジトリの指定ブランチの変更をローカルに取り込む。

  • git fetch origin ブランチ名
    他の人が作成したブランチを取り込む。

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?