差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
linux:git [2019/09/13 09:22] – [強制的にリモートブランチの最新に合わせる] ともやん | linux:git [2023/09/01 13:18] (現在) – [参考文献] ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
====== Git - 分散型バージョン管理システム ====== | ====== Git - 分散型バージョン管理システム ====== | ||
+ | <WRAP logo> | ||
+ | | {{: | ||
+ | | [[https:// | ||
+ | </ | ||
+ | |||
+ | ===== リポジトリを複製 ===== | ||
+ | |||
+ | ==== フルクローン (full clone) [git clone] ==== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Cloning into ' | ||
+ | remote: Enumerating objects: 171, done. | ||
+ | remote: Counting objects: 100% (171/171), done. | ||
+ | remote: Compressing objects: 100% (115/115), done. | ||
+ | remote: Total 24562 (delta 82), reused 103 (delta 48), pack-reused 24391 | ||
+ | Receiving objects: 100% (24562/ | ||
+ | Resolving deltas: 100% (21043/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== シャロークローン (shallow clone) [git clone --depth 1] ==== | ||
+ | 開発リポジトリなどをビルド用に最新履歴のみ高速に複製する🤤\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Cloning into ' | ||
+ | remote: Enumerating objects: 1820, done. | ||
+ | remote: Counting objects: 100% (1820/ | ||
+ | remote: Compressing objects: 100% (884/884), done. | ||
+ | remote: Total 1820 (delta 1149), reused 1276 (delta 912), pack-reused 0 | ||
+ | Receiving objects: 100% (1820/ | ||
+ | Resolving deltas: 100% (1149/ | ||
+ | </ | ||
+ | </ | ||
+ | **'' | ||
+ | |||
+ | <WRAP round tip 90%> | ||
+ | とても高速に clone 出来るが master ブランチの fetch しか出来なくなる😅\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | [core] | ||
+ | repositoryformatversion = 0 | ||
+ | filemode = true | ||
+ | bare = false | ||
+ | logallrefupdates = true | ||
+ | [remote " | ||
+ | url = https:// | ||
+ | fetch = +refs/ | ||
+ | [branch " | ||
+ | remote = origin | ||
+ | merge = refs/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 通常の clone と同様に fetch できるように直すことは可能🤤\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | +refs/ | ||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | +refs/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 通常の clone では '' | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Cloning into ' | ||
+ | remote: Enumerating objects: 26193, done. | ||
+ | remote: Counting objects: 100% (72/72), done. | ||
+ | remote: Compressing objects: 100% (52/52), done. | ||
+ | remote: Total 26193 (delta 32), reused 38 (delta 17), pack-reused 26121 | ||
+ | Receiving objects: 100% (26193/ | ||
+ | Resolving deltas: 100% (22303/ | ||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | [core] | ||
+ | repositoryformatversion = 0 | ||
+ | filemode = true | ||
+ | bare = false | ||
+ | logallrefupdates = true | ||
+ | [remote " | ||
+ | url = https:// | ||
+ | fetch = +refs/ | ||
+ | [branch " | ||
+ | remote = origin | ||
+ | merge = refs/ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== サブモジュールのシャロークローン [--recommend --depth 1] ==== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Submodule ' | ||
+ | Submodule ' | ||
+ | Submodule ' | ||
+ | Submodule ' | ||
+ | Cloning into '/ | ||
+ | Cloning into '/ | ||
+ | Cloning into '/ | ||
+ | Cloning into '/ | ||
+ | Submodule path ' | ||
+ | Submodule path ' | ||
+ | remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 | ||
+ | remote: Enumerating objects: 105, done. | ||
+ | remote: Counting objects: 100% (105/105), done. | ||
+ | remote: Compressing objects: 100% (54/54), done. | ||
+ | remote: Total 57 (delta 42), reused 7 (delta 1), pack-reused 0 | ||
+ | Unpacking objects: 100% (57/57), 19.71 KiB | 420.00 KiB/s, done. | ||
+ | From https:// | ||
+ | * branch | ||
+ | Submodule path ' | ||
+ | remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 | ||
+ | remote: Enumerating objects: 9, done. | ||
+ | remote: Counting objects: 100% (9/9), done. | ||
+ | remote: Compressing objects: 100% (4/4), done. | ||
+ | remote: Total 5 (delta 2), reused 3 (delta 0), pack-reused 0 | ||
+ | Unpacking objects: 100% (5/5), 663 bytes | 110.00 KiB/s, done. | ||
+ | From https:// | ||
+ | * branch | ||
+ | Submodule path ' | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== リモートリポジトリ ===== | ||
+ | |||
+ | ==== ローカルリポジトリのリモート URL を表示/ | ||
+ | クローンしたローカルリポジトリのリモート URL を表示する...🤔\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | https:// | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ローカルリポジトリのリモート URL を SSH の URL に変更する😊\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | git@github.com: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ローカルリポジトリのリモート URL を HTTPS の URL に変更する😊\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | https:// | ||
+ | </ | ||
+ | </ | ||
===== リモートブランチの最新に合わせる ===== | ===== リモートブランチの最新に合わせる ===== | ||
- | <code> | + | <WRAP color_term> |
- | $ git pull | + | <WRAP color_command>< |
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
Already up to date. | Already up to date. | ||
- | </code> | + | </pre></ |
+ | </ | ||
+ | |||
+ | |||
+ | ==== ローカルのファイルやディレクトリへの変更を破棄する ==== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
==== 強制的にリモートブランチの最新に合わせる ==== | ==== 強制的にリモートブランチの最新に合わせる ==== | ||
リモートの最新を取ってくる。\\ | リモートの最新を取ってくる。\\ | ||
- | <code> | + | <WRAP color_term> |
- | $ git fetch origin master | + | <WRAP color_command>< |
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
From git:// | From git:// | ||
* branch | * branch | ||
- | </code> | + | </pre></ |
+ | </ | ||
+ | |||
ローカルの master を、リモート追跡の master にリセットする。\\ | ローカルの master を、リモート追跡の master にリセットする。\\ | ||
- | <code> | + | <WRAP color_term> |
- | $ git reset --hard origin/ | + | <WRAP color_command>< |
- | </code> | + | <b class=GRN> |
+ | </pre></ | ||
+ | </ | ||
+ | |||
+ | |||
+ | **Untracked files** を(-d ディレクトリを含めて)削除する。\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | **submodule** の **new commits, modified content** をリセットする。\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | **submodule** の **new commits** をリセットする。\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
+ | |||
ローカルの状態を確認する。\\ | ローカルの状態を確認する。\\ | ||
- | <code> | + | <WRAP color_term> |
- | $ git status | + | <WRAP color_command>< |
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
On branch master | On branch master | ||
Your branch is up to date with ' | Your branch is up to date with ' | ||
nothing to commit, working tree clean | nothing to commit, working tree clean | ||
- | </code> | + | </pre></ |
+ | </ | ||
+ | |||
+ | ===== タグ/ | ||
+ | |||
+ | ==== タグ ==== | ||
+ | リモートのタグを取得\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Already up to date. | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | タグの一覧表示\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | wxPy-2.8.0.1 | ||
+ | wxPy-2.8.0.2 | ||
+ | ... | ||
+ | wxPy-3.0.1.1 | ||
+ | wxPy-3.0.2.0 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 現在のブランチの直前のコミットに対してタグを付ける\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | タグをチェックアウトする\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Updating files: 100% (12896/ | ||
+ | Note: switching to ' | ||
+ | |||
+ | You are in ' | ||
+ | changes and commit them, and you can discard any commits you make in this | ||
+ | state without impacting any branches by switching back to a branch. | ||
+ | |||
+ | If you want to create a new branch to retain commits you create, you may | ||
+ | do so (now or later) by using -c with the switch command. Example: | ||
+ | |||
+ | git switch -c & | ||
+ | |||
+ | Or undo this operation with: | ||
+ | |||
+ | git switch - | ||
+ | |||
+ | Turn off this advice by setting config variable advice.detachedHead to false | ||
+ | |||
+ | HEAD is now at 67db99581e set revisions for externals | ||
+ | |||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | * (HEAD detached at wxPy-3.0.2.0) | ||
+ | master | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | タグからブランチを作成する\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Switched to a new branch ' | ||
+ | |||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | master | ||
+ | * wxPyhton-3.0.2.0 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== ブランチ ==== | ||
+ | 現在のブランチを表示\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | * master | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | リモートブランチの一覧表示\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | * master | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | ... | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | タグ(wxPy-3.0.2.0)からブランチ(wxPyhton-3.0.2.0)を作成する\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
===== トラブルシューティング ===== | ===== トラブルシューティング ===== | ||
==== 編集もしていないのにステータスで確認すると modified: が出続ける ==== | ==== 編集もしていないのにステータスで確認すると modified: が出続ける ==== | ||
- | <code> | + | <WRAP color_term> |
- | $ git status | + | <WRAP color_command>< |
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
On branch master | On branch master | ||
Your branch is up to date with ' | Your branch is up to date with ' | ||
Changes not staged for commit: | Changes not staged for commit: | ||
- | (use "git add <file> | + | (use "git add <file> |
- | (use "git checkout -- <file> | + | (use "git checkout -- <file> |
modified: | modified: | ||
行 46: | 行 406: | ||
no changes added to commit (use "git add" and/or "git commit -a") | no changes added to commit (use "git add" and/or "git commit -a") | ||
- | </code> | + | </pre></ |
+ | </ | ||
編集を破棄する為に以下を実行してもステータスで確認すると modified: が出続ける。 | 編集を破棄する為に以下を実行してもステータスで確認すると modified: が出続ける。 | ||
- | <code> | + | <WRAP color_term> |
- | $ git checkout . | + | <WRAP color_command>< |
- | $ git checkout -- * | + | <b class=GRN> |
- | $ git reset --hard origin/ | + | <b class=GRN> |
- | </code> | + | <b class=GRN> |
+ | </pre></ | ||
+ | </ | ||
差分を確認するとファイルパーミッションの変更まで検知している。 | 差分を確認するとファイルパーミッションの変更まで検知している。 | ||
- | <code> | + | <WRAP color_term> |
- | $ git diff .eslintignore | + | <WRAP color_command>< |
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
diff --git a/ | diff --git a/ | ||
old mode 100644 | old mode 100644 | ||
new mode 100755 | new mode 100755 | ||
- | </code> | + | </pre></ |
+ | </ | ||
解決策はファイルパーミッションの変更を無視する。 | 解決策はファイルパーミッションの変更を無視する。 | ||
- | <code> | + | <WRAP color_term> |
- | $ git config core.filemode false | + | <WRAP color_command>< |
- | $ git config -l | + | <b class=GRN> |
- | core.repositoryformatversion=0 | + | <b class=GRN> |
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | .repositoryformatversion=0 | ||
core.filemode=false | core.filemode=false | ||
core.bare=false | core.bare=false | ||
行 72: | 行 445: | ||
branch.master.remote=origin | branch.master.remote=origin | ||
branch.master.merge=refs/ | branch.master.merge=refs/ | ||
- | $ git status | + | </ |
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
On branch master | On branch master | ||
Your branch is up to date with ' | Your branch is up to date with ' | ||
nothing to commit, working tree clean | nothing to commit, working tree clean | ||
- | </code> | + | </pre></ |
+ | </WRAP> | ||
===== 参考文献 ===== | ===== 参考文献 ===== | ||
+ | [[https:// | ||
[[http:// | [[http:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | shallow clone\\ | ||
+ | [[qita> | ||
+ | [[qita> | ||
+ | [[https:// | ||
+ | [[gits> | ||
+ | |||
+ | [[gitb> | ||
+ | [[qita> | ||
+ | [[zn> | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[zn> | ||
+ | |||
+ | ==== 付録 ==== | ||
+ | [[tw> | ||
+ | [[tw> | ||