「Gitコマンド備忘録」の版間の差分
提供: Eospedia
行19: | 行19: | ||
** 例えばmasterブランチからdevelブランチを作り、develブランチでコーディングし、それをmasterブランチにマージする時、fast-forwardだとmasterブランチのHEADがdevelブランチの先頭に飛んでくる形になる。 | ** 例えばmasterブランチからdevelブランチを作り、develブランチでコーディングし、それをmasterブランチにマージする時、fast-forwardだとmasterブランチのHEADがdevelブランチの先頭に飛んでくる形になる。 | ||
** 個人的にはffすると分岐や合流のタイミングがわかりにくいので、ff禁止の方が好き。 | ** 個人的にはffすると分岐や合流のタイミングがわかりにくいので、ff禁止の方が好き。 | ||
+ | |||
+ | == リモート系 == | ||
+ | === <u>GitHubでフォークしたリポジトリの初期設定</u> === | ||
+ | * https://help.github.com/en/articles/configuring-a-remote-for-a-fork | ||
+ | |||
+ | [https://github.com/3dem/relion.git relion本家]からフォークしたリポジトリを例にとって説明する。 | ||
+ | |||
+ | まずは自分のリポジトリをクローンしてくる。 | ||
+ | $ git clone https://github.com/kttn8769/relion | ||
+ | |||
+ | $ cd relion | ||
+ | $ git remote -v | ||
+ | origin https://github.com/kttn8769/relion (fetch) | ||
+ | origin https://github.com/kttn8769/relion (push) | ||
+ | 現状は自分のGitHubリポジトリがリモート"origin"として設定されているのみ。 | ||
+ | |||
+ | 本家3dem/relionをリモートとして追加するには、 | ||
+ | $ git remote add upstream https://github.com/3dem/relion.git | ||
+ | とする。 | ||
+ | |||
+ | $ git remote -v | ||
+ | origin https://github.com/kttn8769/relion (fetch) | ||
+ | origin https://github.com/kttn8769/relion (push) | ||
+ | upstream https://github.com/3dem/relion.git (fetch) | ||
+ | upstream https://github.com/3dem/relion.git (push) | ||
+ | リモート"upstream"が追加されている。 | ||
+ | |||
+ | === <u>GitHubでフォークしたリポジトリを最新にする</u> === | ||
+ | * https://help.github.com/en/articles/syncing-a-fork | ||
+ | |||
+ | リモート"upstream"の情報を取ってくる。 | ||
+ | $ git fetch upstream | ||
+ | |||
+ | 自分のローカルリポジトリのmasterブランチに移動。 | ||
+ | $ git checkout master | ||
+ | |||
+ | upstream/masterを自分のローカルリポジトリのmasterへマージする。 | ||
+ | $ git merge upstream/master | ||
+ | |||
+ | 自分のGitHubのリポジトリに反映するにはoriginへpushする。 | ||
+ | $ git push origin master |
2019年5月16日 (木) 07:51時点における版
- (自分が)よく使うGitコマンドを備忘録的に書きつけていきます。
- たまにVSCode(Visual Studio Code)の拡張機能GitLensにおける当該機能についてもメモります。
目次
やり直し系
コミットされたものをステージング状態に戻す
コマンド
$ git reset --soft <commit>
現在のコミット状態を過去の<commit>の時点まで戻す。その間コミットされたものはステージング状態になる。
GitLens
- "Reset to commit"に相当する。
- GitLensで特定のコミットを右クリックし、Reset to commitすればそのコミットまでreset --softされる。
マージ系
fast-forwardマージを禁止する
$ git config --global merge.ff false
- fast-foward(ff) マージ
- 例えばmasterブランチからdevelブランチを作り、develブランチでコーディングし、それをmasterブランチにマージする時、fast-forwardだとmasterブランチのHEADがdevelブランチの先頭に飛んでくる形になる。
- 個人的にはffすると分岐や合流のタイミングがわかりにくいので、ff禁止の方が好き。
リモート系
GitHubでフォークしたリポジトリの初期設定
relion本家からフォークしたリポジトリを例にとって説明する。
まずは自分のリポジトリをクローンしてくる。
$ git clone https://github.com/kttn8769/relion
$ cd relion $ git remote -v origin https://github.com/kttn8769/relion (fetch) origin https://github.com/kttn8769/relion (push)
現状は自分のGitHubリポジトリがリモート"origin"として設定されているのみ。
本家3dem/relionをリモートとして追加するには、
$ git remote add upstream https://github.com/3dem/relion.git
とする。
$ git remote -v origin https://github.com/kttn8769/relion (fetch) origin https://github.com/kttn8769/relion (push) upstream https://github.com/3dem/relion.git (fetch) upstream https://github.com/3dem/relion.git (push)
リモート"upstream"が追加されている。
GitHubでフォークしたリポジトリを最新にする
リモート"upstream"の情報を取ってくる。
$ git fetch upstream
自分のローカルリポジトリのmasterブランチに移動。
$ git checkout master
upstream/masterを自分のローカルリポジトリのmasterへマージする。
$ git merge upstream/master
自分のGitHubのリポジトリに反映するにはoriginへpushする。
$ git push origin master