編集の要約なし
44行目: 44行目:
|<code>git commit -m "Comment"</code> || 変更のコミット
|<code>git commit -m "Comment"</code> || 変更のコミット
|-
|-
|<code>git commit -a -m "Comment"</code> || 一気にステージングかつコミット
|<code>git commit -am "Comment"</code> || 一気にステージングかつコミット
|-
|-
|<code>git commit --amend</code> || 直近のコミットやコメントを修正
|<code>git commit --amend</code> || 直近のコミットやコメントを修正

2025年3月9日 (日) 20:42時点における版

Git/GitHub

Git はLinuxを作ったリーナスによって、カーネルのバージョン管理のために開発された。

  • ブランチ/マージを繰り返しながら気軽に開発や最適化の試行錯誤ができる
  • ブランチを繰り返しmasterから階層が離れるほど不安定バージョンになる
  • ディレクトリを指定した場合は、そのディレクトリ以下にあるすべてのファイルを再帰的に追加
  • GitHub はWeb上のバックアップとしても使える

よく使う操作

コマンド 説明
git config --list 設定オプションを表示
git config --global alias.bv 'branch -v' エイリアスを設定
git config --global --unset alias.bv エイリアスの解除
git help ヘルプの表示
git status ステージの現状
git status -s ステージの現状(簡略版)
git log 過去の変更履歴を閲覧。HEADポインタの表示
git log -p -2 変更履歴の詳細を2件表示
git log --stat 変更履歴の分量を統計的に表示
git last 'log -1 HEAD'エイリアス。直近のログ
git add 変更をステージ(コンフリクト修正時のマークとしても使える)
git unstage <file> reset HEAD のエイリアス。fileをステージから外す
git checkout -- <file> 変更の巻き戻し
git rm ファイルの追跡を中止(次回コミット時に反映される)
git mv git にファイル名の変更を知らせる
git commit -m "Comment" 変更のコミット
git commit -am "Comment" 一気にステージングかつコミット
git commit --amend 直近のコミットやコメントを修正
git branch ブランチの現状
git branch -v 各ブランチの直近のコミットコメントを表示
git branch --no-merged マージされた事のないブランチ
git branch hoge ブランチの作成
git checkout hoge hogeブランチへ切り替え
git checkout -b fuga fugaブランチを作成しつつ切り替え
git log --oneline --decorate --graph --all マージの歴史
git merge hoge ブランチをマージ(通常はmasterでマージする)
git branch -d hoge ブランチの削除(通常はマージ後に不要になる為)
git diff 直近ステージ済みとの差分を確認
git diff --staged 直近コミットとの差分を確認
git tag タグの確認(リリースポイントとして活用など)

リモート操作

コマンド 説明
git clone --bare my_project my_project.git サーバ用リポジトリの作成
git clone <URL> 指定のプロジェクトをクローン
git remote -v 登録されているリモートプロジェクトを表示
git remote add pb https://github.com/paulboone/ticgit 「pb」でアクセスできるようにする
git remote rename pb paul 「pb」を「paul」にリネーム
git remote rm paul リモート「paul」を削除
git fetch origin 「origin」からプロジェクトの変更情報を取得
git pull origin 「origin」からの変更情報のマージを試みる
git push [remote-name] [branch-name] 修正内容をリモートにプッシュ

参考:https://git-scm.com/book/ja/v2