| (同じ利用者による、間の46版が非表示) | |||
| 1行目: | 1行目: | ||
| *  | [[ファイル:github-logo.jpeg|thumb|Git/GitHub|400px]] | ||
| '''Git''' はLinuxを作ったリーナスによって、カーネルの<strong>バージョン管理のため</strong>に開発された。 | |||
| * ブランチ/マージを繰り返しながら<u>気軽に開発や最適化の試行錯誤</u>ができる | |||
| * ブランチを繰り返しmasterから階層が離れるほど不安定バージョンになる | * ブランチを繰り返しmasterから階層が離れるほど不安定バージョンになる | ||
| * ディレクトリを指定した場合は、そのディレクトリ以下にあるすべてのファイルを再帰的に追加 | * ディレクトリを指定した場合は、そのディレクトリ以下にあるすべてのファイルを再帰的に追加 | ||
| * GitHub は<u>Web上のバックアップ</u>としても使える | |||
| ==TIPs== | |||
| * 別ブランチのファイルをチラ見したい「git show sub:client/components/MyComponent.tsx」 | |||
| * 最初からコミットルール統一しないと後々rebaseの時にコンフリクトが大量発生してrebaseできない | |||
| ==よく使う操作== | ==よく使う操作== | ||
| 19行目: | 28行目: | ||
| |<code>git status -s</code> || ステージの現状(簡略版) | |<code>git status -s</code> || ステージの現状(簡略版) | ||
| |- | |- | ||
| |<code>git log</code> ||  | |<code>git log</code> || 過去の変更履歴を閲覧。HEADポインタの表示 | ||
| |- | |||
| |<code>git log -p -2</code> || 変更履歴の詳細を2件表示 | |||
| |- | |||
| |<code>git log --stat</code> || 変更履歴の分量を統計的に表示 | |||
| |- | |- | ||
| |<code>git last</code> || 'log -1 HEAD'エイリアス。直近のログ | |<code>git last</code> || 'log -1 HEAD'エイリアス。直近のログ | ||
| |- | |- | ||
| |<code>git add</code> || 変更をステージ(コンフリクト修正時のマークとしても使える) | |<code>git add</code> || 変更をステージ(コンフリクト修正時のマークとしても使える) | ||
| |- | |||
| |<code>git unstage <file></code> || reset HEAD のエイリアス。fileをステージから外す | |||
| |- | |||
| |<code>git checkout -- <file></code> || 変更の巻き戻し | |||
| |- | |||
| |<code>git rm</code> || ファイルの追跡を中止(次回コミット時に反映される) | |||
| |- | |||
| |<code>git mv</code> || git にファイル名の変更を知らせる | |||
| |- | |- | ||
| |<code>git commit -m "Comment"</code> || 変更のコミット | |<code>git commit -m "Comment"</code> || 変更のコミット | ||
| |- | |- | ||
| |<code>git commit - | |<code>git commit -am "Comment"</code> || 一気にステージングかつコミット | ||
| |- | |||
| |<code>git commit --amend</code> || 直近のコミットやコメントを修正 | |||
| |- | |- | ||
| |<code>git branch</code> || ブランチの現状 | |<code>git branch</code> || ブランチの現状 | ||
| 46行目: | 69行目: | ||
| |- | |- | ||
| |<code>git branch -d hoge</code> || ブランチの削除(通常はマージ後に不要になる為) | |<code>git branch -d hoge</code> || ブランチの削除(通常はマージ後に不要になる為) | ||
| |- | |||
| |<code>git diff</code> || 直近ステージ済みとの差分を確認 | |||
| |- | |||
| |<code>git diff --staged</code> || 直近コミットとの差分を確認 | |||
| |- | |||
| |<code>git tag</code> || タグの確認(リリースポイントとして活用など) | |||
| |} | |||
| ===リモート操作=== | |||
| {| class="wikitable" summary="リモート操作" | |||
| !コマンド !! 説明 | |||
| |- | |||
| |<code>git clone --bare my_project my_project.git</code> || サーバ用リポジトリの作成 | |||
| |- | |||
| |<code>git clone <URL></code> || 指定のプロジェクトをクローン | |||
| |- | |||
| |<code>git remote -v<code> || 登録されているリモートプロジェクトを表示 | |||
| |- | |||
| |<code>git remote add pb <nowiki>https://github.com/paulboone/ticgit</nowiki></code> || 「pb」でアクセスできるようにする | |||
| |- | |||
| |<code>git remote rename pb paul</code> || 「pb」を「paul」にリネーム | |||
| |- | |||
| |<code>git remote rm paul</code> || リモート「paul」を削除 | |||
| |- | |||
| |<code>git fetch origin</code> || 「origin」からプロジェクトの変更情報を取得 | |||
| |- | |||
| |<code>git pull origin</code> || 「origin」からの変更情報のマージを試みる | |||
| |- | |||
| |<code>git push [remote-name] [branch-name]</code> || 修正内容をリモートにプッシュ | |||
| |} | |} | ||
| <small>参考:https://git-scm.com/book/ja/v2</small> | <small>参考:https://git-scm.com/book/ja/v2</small> | ||
2025年4月29日 (火) 21:27時点における最新版

Git はLinuxを作ったリーナスによって、カーネルのバージョン管理のために開発された。
- ブランチ/マージを繰り返しながら気軽に開発や最適化の試行錯誤ができる
- ブランチを繰り返しmasterから階層が離れるほど不安定バージョンになる
- ディレクトリを指定した場合は、そのディレクトリ以下にあるすべてのファイルを再帰的に追加
- GitHub はWeb上のバックアップとしても使える
TIPs
- 別ブランチのファイルをチラ見したい「git show sub:client/components/MyComponent.tsx」
- 最初からコミットルール統一しないと後々rebaseの時にコンフリクトが大量発生してrebaseできない
よく使う操作
| コマンド | 説明 | 
|---|---|
| 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] | 修正内容をリモートにプッシュ |