Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

自分用 Git まとめ

Posted at

ローカルリポジトリの作成方法

ファイルの追加、更新、コミットなどの基本コマンド

リモートリポジトリへの操作

リモートリポジトリのクローン

git clone <リモートリポジトリのURL>

リモートリポジトリの追加

git remote add <リモート名> <リモートリポジトリのURL>

リモートリポジトリから変更を取得

git pull <リモート名> <ブランチ名>

ローカルの変更をリモートにプッシュ

git push <リモート名> <ブランチ名>

リモートブランチの確認

git branch -r

リモートリポジトリの変更を確認

git remote show <リモート名>

リモート名の確認

git remote

master/feature/develop/bugfixブランチの役割

master ブランチ
特徴:本番環境にデプロイする準備が整った安定したコードのバージョンを表す。
develop ブランチ
派生元:master
役割:新しい機能の追加やバグ修正
特徴:開発者が日常的に作業を行うブランチ
   開発が一定の段階に進んだときには、 masterブランチにマージされる
Feature ブランチ
派生元:develop
役割:新しい機能を開発
特徴:機能が完成するまでこのブランチで作業が行われる
   機能が完成したら、develop ブランチにマージされる
Bugfix ブランチ
派生元:masterやdevelop
役割:バグの修正
特徴:バグが修正されると、派生元のブランチにマージされる

ブランチの切り替え

古いバージョンでの切り替え

# 既存のブランチに切り替える
git checkout branch-name
# 新しいブランチを作成して切り替える(ショートカット)
git checkout -b new-branch-name

新しいバージョンでの切り替え

# 既存のブランチに切り替える
git switch branch-name
# 新しいブランチを作成して切り替える(ショートカット)
git switch -c new-branch-name

ローカルリポジトリへのブランチの作成、タグの作成

ブランチ作成

git checkout -b new-branch-name

new-branch-name という名前の新しいブランチが作成され、そのブランチに切り替えられます。
タグ
タグは、リポジトリの特定のコミットに意味やバージョン番号を関連付けるための方法です。

-タグの例-
・リリースバージョン("Release version 1.0")
・リリースイベント( "Release event on December 31, 2022")
・重要な機能追加("Added feature X")
・セキュリティフィックス("Fixed security vulnerability")
・リリース候補("Release candidate for version 2.0")

# 現在のコミットに lightweight タグを作成する
git tag tag-name

# 特定のコミットに lightweight タグを作成する
git tag tag-name commit-hash

lightweight タグは軽量で、単なるポインタのようなものです。

# 現在のコミットに annotated タグを作成する
git tag -a tag-name -m "タグのメッセージ"

# 特定のコミットに annotated タグを作成する
git tag -a tag-name -m "タグのメッセージ" commit-hash

重みのある(annotated)タグを作成するには -a オプションを使用します。

履歴の確認

git log

コミットログの表示
最新のコミットから過去のコミットまでの詳細なログが表示されます。

git log <file>

特定のファイルに対する変更履歴を表示します。

git log -p

各コミットでの具体的な変更内容(パッチ)を表示します。

git log --graph --oneline --all

コミット間のブランチやマージの構造をグラフィカルに表示する。

過去のコミットに戻す

git checkout <commit-hash>

<commit-hash>は過去のコミットのハッシュ値です。このコマンドを実行すると、指定したコミットの状態にワーキングディレクトリが変更されます。
コミットハッシュは通常、40文字の16進数で表現されます。

git branch new-branch-name <commit-hash>
git checkout new-branch-name

指定したコミットから新しいブランチを作成し、そのブランチで作業できます。

マージの仕組みの理解

Gitのconfig 設定

$ git config --list

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?