文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== Git - 分散型バージョン管理システム ====== <WRAP logo> | {{:linux:git-logo.svg?300|Git Logo}} | | [[https://commons.wikimedia.org/wiki/File:Git-logo.svg|File:Git-logo.svg - Wikimedia Commons]] | </WRAP> ===== リポジトリを複製 ===== ==== フルクローン (full clone) [git clone] ==== <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> clone https://github.com/SoftEtherVPN/SoftEtherVPN.git </pre></html></WRAP> <WRAP color_result><html><pre> Cloning into 'SoftEtherVPN'... 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/24562), 526.67 MiB | 1.91 MiB/s, done. Resolving deltas: 100% (21043/21043), done. </pre></html></WRAP> </WRAP> ==== シャロークローン (shallow clone) [git clone --depth 1] ==== 開発リポジトリなどをビルド用に最新履歴のみ高速に複製する🤤\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> clone --depth 1 https://github.com/SoftEtherVPN/SoftEtherVPN.git </pre></html></WRAP> <WRAP color_result><html><pre> Cloning into 'SoftEtherVPN'... remote: Enumerating objects: 1820, done. remote: Counting objects: 100% (1820/1820), done. remote: Compressing objects: 100% (884/884), done. remote: Total 1820 (delta 1149), reused 1276 (delta 912), pack-reused 0 Receiving objects: 100% (1820/1820), 9.37 MiB | 2.86 MiB/s, done. Resolving deltas: 100% (1149/1149), done. </pre></html></WRAP> </WRAP> **''--depth 1''**: コミット履歴を指定の深さ(最新のみ)に切り捨てることを指示する。[[https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt|Git - git-clone Documentation]]\\ <WRAP round tip 90%> とても高速に clone 出来るが master ブランチの fetch しか出来なくなる😅\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>cat</b> SoftEtherVPN/.git/config </pre></html></WRAP> <WRAP color_result><html><pre> [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://github.com/SoftEtherVPN/SoftEtherVPN.git fetch = +refs/heads/<b class=DiYE>master</b>:refs/remotes/origin/<b class=DiYE>master</b> [branch "master"] remote = origin merge = refs/heads/master </pre></html></WRAP> </WRAP> 通常の clone と同様に fetch できるように直すことは可能🤤\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>cd</b> SoftEtherVPN <b class=GRN>$</b> <b class=HIY>git</b> config remote.origin.fetch </pre></html></WRAP> <WRAP color_result><html><pre> +refs/heads/master:refs/remotes/origin/master </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' <b class=GRN>$</b> <b class=HIY>git</b> config remote.origin.fetch </pre></html></WRAP> <WRAP color_result><html><pre> +refs/heads/*:refs/remotes/origin/* </pre></html></WRAP> </WRAP> 通常の clone では ''fetch = +refs/heads/*:refs/remotes/origin/*'' である🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> clone https://github.com/SoftEtherVPN/SoftEtherVPN.git SoftEtherVPN-all </pre></html></WRAP> <WRAP color_result><html><pre> Cloning into 'SoftEtherVPN-all'... 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/26193), 527.27 MiB | 2.16 MiB/s, done. Resolving deltas: 100% (22303/22303), done. </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>cat</b> SoftEtherVPN-all/.git/config </pre></html></WRAP> <WRAP color_result><html><pre> [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://github.com/SoftEtherVPN/SoftEtherVPN.git fetch = +refs/heads/<b class=DiYE>*</b>:refs/remotes/origin/<b class=DiYE>*</b> [branch "master"] remote = origin merge = refs/heads/master </pre></html></WRAP> </WRAP> </WRAP> ==== サブモジュールのシャロークローン [--recommend --depth 1] ==== <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> submodule update --init --recursive --recommend-shallow --depth 1 </pre></html></WRAP> <WRAP color_result><html><pre> Submodule '3rdparty/BLAKE2' (https://github.com/BLAKE2/BLAKE2.git) registered for path '3rdparty/BLAKE2' Submodule '3rdparty/tinydir' (https://github.com/cxong/tinydir.git) registered for path '3rdparty/tinydir' Submodule 'src/Mayaqua/3rdparty/cpu_features' (https://github.com/google/cpu_features.git) registered for path 'src/Mayaqua/3rdparty/cpu_features' Submodule 'src/libhamcore' (https://github.com/SoftEtherVPN/libhamcore.git) registered for path 'src/libhamcore' Cloning into '/home/tomoyan/work/SoftEtherVPN/3rdparty/BLAKE2'... Cloning into '/home/tomoyan/work/SoftEtherVPN/3rdparty/tinydir'... Cloning into '/home/tomoyan/work/SoftEtherVPN/src/Mayaqua/3rdparty/cpu_features'... Cloning into '/home/tomoyan/work/SoftEtherVPN/src/libhamcore'... Submodule path '3rdparty/BLAKE2': checked out 'b52178a376ca85a8ffe50492263c2a5bc0fa4f46' Submodule path '3rdparty/tinydir': checked out 'ec6bff2043eaac3ad25423705e63a781762a0dfd' 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://github.com/google/cpu_features * branch 26133d3b620c2c27f31d571efd27371100f891e9 -> FETCH_HEAD Submodule path 'src/Mayaqua/3rdparty/cpu_features': checked out '26133d3b620c2c27f31d571efd27371100f891e9' 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://github.com/SoftEtherVPN/libhamcore * branch b7f5d8d735b280fc77673c4a29f0436a92ca6660 -> FETCH_HEAD Submodule path 'src/libhamcore': checked out 'b7f5d8d735b280fc77673c4a29f0436a92ca6660' </pre></html></WRAP> </WRAP> ===== リモートリポジトリ ===== ==== ローカルリポジトリのリモート URL を表示/変更 ==== クローンしたローカルリポジトリのリモート URL を表示する...🤔\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>cd</b> jupyter-binder <b class=GRN>$</b> <b class=HIY>git</b> remote get-url origin </pre></html></WRAP> <WRAP color_result><html><pre> https://github.com/tomoyan596/jupyter-binder.git </pre></html></WRAP> </WRAP> ローカルリポジトリのリモート URL を SSH の URL に変更する😊\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> remote set-url origin git@github.com:tomoyan596/jupyter-binder.git <b class=GRN>$</b> <b class=HIY>git</b> remote get-url origin </pre></html></WRAP> <WRAP color_result><html><pre> git@github.com:tomoyan596/jupyter-binder.git </pre></html></WRAP> </WRAP> ローカルリポジトリのリモート URL を HTTPS の URL に変更する😊\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> remote set-url origin https://github.com/tomoyan596/jupyter-binder.git <b class=GRN>$</b> <b class=HIY>git</b> remote get-url origin </pre></html></WRAP> <WRAP color_result><html><pre> https://github.com/tomoyan596/jupyter-binder.git </pre></html></WRAP> </WRAP> ===== リモートブランチの最新に合わせる ===== <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> pull </pre></html></WRAP> <WRAP color_result><html><pre> Already up to date. </pre></html></WRAP> </WRAP> ==== ローカルのファイルやディレクトリへの変更を破棄する ==== <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> checkout --force </pre></html></WRAP> </WRAP> ==== 強制的にリモートブランチの最新に合わせる ==== リモートの最新を取ってくる。\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> fetch origin master </pre></html></WRAP> <WRAP color_result><html><pre> From git://git.tomoyan.net/project_name * branch master -> FETCH_HEAD </pre></html></WRAP> </WRAP> ローカルの master を、リモート追跡の master にリセットする。\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> reset --hard origin/master </pre></html></WRAP> </WRAP> **Untracked files** を(-d ディレクトリを含めて)削除する。\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> clean -df </pre></html></WRAP> </WRAP> **submodule** の **new commits, modified content** をリセットする。\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> submodule foreach --recursive git reset --hard </pre></html></WRAP> </WRAP> **submodule** の **new commits** をリセットする。\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> submodule update --init </pre></html></WRAP> </WRAP> ローカルの状態を確認する。\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> status </pre></html></WRAP> <WRAP color_result><html><pre> On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean </pre></html></WRAP> </WRAP> ===== タグ/ブランチの使い方 ===== ==== タグ ==== リモートのタグを取得\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> pull --tags </pre></html></WRAP> <WRAP color_result><html><pre> Already up to date. </pre></html></WRAP> </WRAP> タグの一覧表示\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> tag </pre></html></WRAP> <WRAP color_result><html><pre> wxPy-2.8.0.1 wxPy-2.8.0.2 ... wxPy-3.0.1.1 wxPy-3.0.2.0 </pre></html></WRAP> </WRAP> 現在のブランチの直前のコミットに対してタグを付ける\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> tag wxPy-3.0.2.0 </pre></html></WRAP> </WRAP> タグをチェックアウトする\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> checkout wxPy-3.0.2.0 </pre></html></WRAP> <WRAP color_result><html><pre> Updating files: 100% (12896/12896), done. Note: switching to 'wxPy-3.0.2.0'. You are in 'detached HEAD' state. You can look around, make experimental 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 <new-branch-name> 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 </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> branch </pre></html></WRAP> <WRAP color_result><html><pre> * (HEAD detached at wxPy-3.0.2.0) master </pre></html></WRAP> </WRAP> タグからブランチを作成する\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> checkout -b wxPyhton-3.0.2.0 </pre></html></WRAP> <WRAP color_result><html><pre> Switched to a new branch 'wxPyhton-3.0.2.0' </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> branch master * wxPyhton-3.0.2.0 </pre></html></WRAP> </WRAP> ==== ブランチ ==== 現在のブランチを表示\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> branch </pre></html></WRAP> <WRAP color_result><html><pre> * master </pre></html></WRAP> </WRAP> リモートブランチの一覧表示\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> branch -a </pre></html></WRAP> <WRAP color_result><html><pre> * master remotes/origin/HEAD -> origin/master remotes/origin/SOC2007_UNITTEST ... remotes/origin/wxPy-2.9.3.x remotes/origin/wxPyhton-2.9.2 </pre></html></WRAP> </WRAP> タグ(wxPy-3.0.2.0)からブランチ(wxPyhton-3.0.2.0)を作成する\\ <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> checkout -b wxPyhton-3.0.2.0 wxPy-3.0.2.0 </pre></html></WRAP> </WRAP> ===== トラブルシューティング ===== ==== 編集もしていないのにステータスで確認すると modified: が出続ける ==== <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> status </pre></html></WRAP> <WRAP color_result><html><pre> On branch master Your branch is up to date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: .eslintignore modified: .eslintrc modified: .github/PULL_REQUEST_TEMPLATE.md modified: tool/unicode.js modified: tool/update_deps.js modified: tool/wrap_keyword_regexp.js no changes added to commit (use "git add" and/or "git commit -a") </pre></html></WRAP> </WRAP> 編集を破棄する為に以下を実行してもステータスで確認すると modified: が出続ける。 <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> checkout . <b class=GRN>$</b> <b class=HIY>git</b> checkout -- * <b class=GRN>$</b> <b class=HIY>git</b> reset --hard origin/master </pre></html></WRAP> </WRAP> 差分を確認するとファイルパーミッションの変更まで検知している。 <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> diff .eslintignore </pre></html></WRAP> <WRAP color_result><html><pre> diff --git a/.eslintignore b/.eslintignore old mode 100644 new mode 100755 </pre></html></WRAP> </WRAP> 解決策はファイルパーミッションの変更を無視する。 <WRAP color_term> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> config core.filemode false <b class=GRN>$</b> <b class=HIY>git</b> config -l </pre></html></WRAP> <WRAP color_result><html><pre> .repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true remote.origin.url=git://github.com/ajaxorg/ace.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master </pre></html></WRAP> <WRAP color_command><html><pre> <b class=GRN>$</b> <b class=HIY>git</b> status </pre></html></WRAP> <WRAP color_result><html><pre> On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean </pre></html></WRAP> </WRAP> ===== 参考文献 ===== [[https://www.atmarkit.co.jp/ait/articles/2003/05/news006.html|【 git clone 】コマンド――Gitのリポジトリを複製する:Linux基本コマンドTips(381) - @IT]]\\ [[http://www-creators.com/archives/1097|git pull を強制し、リモートでローカルを上書きする方法 | WWWクリエイターズ]]\\ [[https://stackoverflow.com/questions/10906554/how-do-i-revert-my-changes-to-a-git-submodule|How do I revert my changes to a git submodule? - Stack Overflow]]\\ [[https://stackoverflow.com/questions/26957237/how-to-make-git-clone-faster-with-multiple-threads|How to make git clone faster with multiple threads? - Stack Overflow]]\\ shallow clone\\ [[qita>usamik26/items/7bfa61b31344206077fb|git リポジトリの最新の履歴だけを取得する shallow clone - Qiita]]\\ [[qita>sonots/items/ce08c30d161ea0b4d5fd|git で shallow clone - Qiita]]\\ [[https://pocke.hatenablog.com/entry/2018/12/19/015644|git: shallow cloneしてすぐunshallowする - pockestrap]]\\ [[gits>docs/git-clone#Documentation/git-clone.txt---depthltdepthgt|Git - git-clone Documentation]]\\ [[gitb>jp/2021-01-13-get-up-to-speed-with-partial-clone-and-shallow-clone/|パーシャルクローンとシャロークローンを活用しよう - GitHubブログ]]\\ [[qita>tsuyoshi_cho/items/8ee621805332249a6fa5|git のクローンを最小量にする(サブモジュールを含めたshallow clone) - Qiita]]\\ [[zn>snowcait/articles/d44d6b2bed2e4b29ada4|Git で shallow clone するときに全ブランチの最新履歴を取得する]]\\ [[https://サーバー構築と設定.com/?p=1434|Git サーバーを CentOS 7 で構築する方法と設定手順 - サーバー構築と設定 ~初心者にも分かりやすく解説~]]\\ [[https://www.nekotricolor.com/entry/theory-of-bare-and-non-bare-repository-manage-wordpress-themes-with-git|ベアリポジトリとノンベアリポジトリ:理論編〜GitでWordpressのテーマを管理 - トリコロールな猫]]\\ [[https://www.nekotricolor.com/entry/practice-of-bare-and-non-bare-repository-manage-wordpress-themes-with-git|ベアリポジトリとノンベアリポジトリ:実践編〜GitでWordPressのテーマを管理 - トリコロールな猫]]\\ [[https://atmarkit.itmedia.co.jp/ait/articles/1701/24/news141.html|これでもう怖くない、Git/GitHubにおけるリモートリポジトリの作成、確認、変更、更新時の基本5コマンド]]\\ [[zn>kazuwombat/articles/eced2915b6adff|git reset —hardしてしまった時に元に戻す方法]]\\ ==== 付録 ==== [[tw>tomoyan596/status/1375662745056464897|git の shallow clone についてまとめておこうかなぁ🤔]]\\ [[tw>tomoyan596sp/status/1635375497503985665|Gitのベアリポジトリとノンベアリポジトリについて🤔]]\\ linux/git.txt 最終更新: 2023/09/01 13:18by ともやん