{"id":101,"date":"2021-10-17T23:17:06","date_gmt":"2021-10-17T15:17:06","guid":{"rendered":"http:\/\/47.98.165.52\/?p=101"},"modified":"2021-11-09T19:24:04","modified_gmt":"2021-11-09T11:24:04","slug":"git%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba","status":"publish","type":"post","link":"\/?p=101","title":{"rendered":"Git\u670d\u52a1\u5668\u642d\u5efa"},"content":{"rendered":"<h3>1\u3001 \u9996\u5148\u68c0\u67e5\u7535\u8111\u662f\u5426\u5df2\u5b89\u88c5git\u8fdc\u7a0b\u670d\u52a1\uff0c\u5982\u6ca1\u6709Git\u670d\u52a1\u8bf7\u6267\u884c\u7b2c\u4e09\u6b65<\/h3>\n<pre><code class=\"language-shell\">rpm -qa git<\/code><\/pre>\n<h3>2\u3001 \u5982\u679c\u6267\u884c\u5b8c\u7b2c\u4e00\u6b65\u53d1\u73b0\u7cfb\u7edf\u5b89\u88c5\u4e86git \u670d\u52a1\uff0c\u8bf7\u6267\u884c\u6b64\u6b65\u9aa4<\/h3>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ ~]# yum remove git\nLoaded plugins: fastestmirror\nResolving Dependencies\n--&gt; Running transaction check\n---&gt; Package git.x86_64 0:1.8.3.1-23.el7_8 will be erased\n--&gt; Processing Dependency: git = 1.8.3.1-23.el7_8 for package: perl-Git-1.8.3.1-23.el7_8.noarch\n--&gt; Running transaction check\n---&gt; Package perl-Git.noarch 0:1.8.3.1-23.el7_8 will be erased\n--&gt; Finished Dependency Resolution\n\nDependencies Resolved\n\n====================================================================================================\n Package               Arch                Version                         Repository          Size\n====================================================================================================\nRemoving:\n git                   x86_64              1.8.3.1-23.el7_8                @base               22 M\nRemoving for dependencies:\n perl-Git              noarch              1.8.3.1-23.el7_8                @base               57 k\n\nTransaction Summary\n====================================================================================================\nRemove  1 Package (+1 Dependent package)\n\nInstalled size: 22 M\nIs this ok [y\/N]: y\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : perl-Git-1.8.3.1-23.el7_8.noarch                                                 1\/2\n  Erasing    : git-1.8.3.1-23.el7_8.x86_64                                                      2\/2\n  Verifying  : git-1.8.3.1-23.el7_8.x86_64                                                      1\/2\n  Verifying  : perl-Git-1.8.3.1-23.el7_8.noarch                                                 2\/2\n\nRemoved:\n  git.x86_64 0:1.8.3.1-23.el7_8\n\nDependency Removed:\n  perl-Git.noarch 0:1.8.3.1-23.el7_8\n\nComplete!\n<\/code><\/pre>\n<h3>3\u3001 \u521b\u5efaGit\u5b89\u88c5\u76ee\u5f55<\/h3>\n<pre><code class=\"language-shell\">mkdir -v \/usr\/local\/git<\/code><\/pre>\n<h3>4\u3001 \u4e0b\u8f7dGit\u6e90\u7801\u5b89\u88c5\u5305<\/h3>\n<p>\u6700\u65b0\u7248\u672c\u5730\u5740:<a href=\"https:\/\/github.com\/git-for-windows\/git\/releases\/\">https:\/\/github.com\/git-for-windows\/git\/releases\/<\/a><\/p>\n<pre><code class=\"language-shell\">wget https:\/\/codeload.github.com\/git\/git\/tar.gz\/v2.17.1<\/code><\/pre>\n<h3>5\u3001 \u89e3\u538bGit\u6e90\u7801\u5305<\/h3>\n<pre><code class=\"language-shell\">tar -zxvf git-2.17.1.tar.gz<\/code><\/pre>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git]# ls\ngit-2.17.1  git-2.17.1.tar.gz<\/code><\/pre>\n<h3>6\u3001 \u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\u5f00\u59cb\u8fdb\u884c\u7f16\u8bd1\u64cd\u4f5c,\u5e76\u6307\u5b9aGit\u5b89\u88c5\u8def\u5f84<\/h3>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git]# cd git-2.17.1\n[root@iZbp159egvvktszc82dr5xZ git-2.17.1]# make prefix=\/usr\/local\/git all<\/code><\/pre>\n<h4>\u91cd\u65b0\u7f16\u8bd1\u7684\u8fc7\u7a0b\u53ef\u80fd\u9047\u5230\u7684\u9519\u8bef<\/h4>\n<p>\u5728\u4f7f\u7528\u547d\u4ee4 <code>make<\/code> \u91cd\u65b0\u7f16\u8bd1 Git \u7684\u67d0\u4e9b\u6e90\u6587\u4ef6\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u8fd9\u4e9b\u9519\u8bef\uff1a<\/p>\n<h5>\u9519\u8bef 1 - FATAL ERROR: OPENSSL\/SSL.H: NO SUCH FILE OR DIRECTORY<\/h5>\n<pre><code class=\"language-shell\">GIT_VERSION = 2.27.0\nmake: curl-config: Command not found\n    * new build flags\n    CC fuzz-commit-graph.o\nIn file included from commit-graph.h:4:0,\n                 from fuzz-commit-graph.c:1:\ngit-compat-util.h:297:25: fatal error: openssl\/ssl.h: No such file or directory\n #include &lt;openssl\/ssl.h&gt;\n                         ^\ncompilation terminated.\nmake: *** [fuzz-commit-graph.o] Error 1\n1234567891011<\/code><\/pre>\n<p>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u67e5\u770b\u4e0e openssl \u76f8\u5173\u7684\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-shell\"># rpm --query --all | grep openssl\nopenssl-libs-1.0.2k-19.el7.x86_64\nopenssl-1.0.2k-19.el7.x86_64\nxmlsec1-openssl-1.2.20-7.el7_4.x86_64\n1234<\/code><\/pre>\n<p>\u8fd9\u662f\u7f3a\u5c11 openssl-devel \u5bfc\u81f4\u7684\uff0c\u6267\u884c\u547d\u4ee4 <code>yum install --assumeyes openssl-devel<\/code> \u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<h5>\u9519\u8bef 2 - FATAL ERROR: CURL\/CURL.H: NO SUCH FILE OR DIRECTORY<\/h5>\n<pre><code class=\"language-shell\">... \u7701\u7565\u90e8\u5206\u4fe1\u606f\nIn file included from http.c:2:0:\nhttp.h:6:23: fatal error: curl\/curl.h: No such file or directory\n #include &lt;curl\/curl.h&gt;\n                       ^\ncompilation terminated.\nmake: *** [http.o] Error 1\n1234567<\/code><\/pre>\n<p>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u67e5\u770b\u4e0e curl \u76f8\u5173\u7684\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-shell\"># rpm --query --all | grep curl\ncurl-7.29.0-54.el7.x86_64\nlibcurl-7.29.0-54.el7.x86_64\npython-pycurl-7.19.0-19.el7.x86_64\n1234<\/code><\/pre>\n<p>\u8fd9\u662f\u7f3a\u5c11 curl-devel \u5bfc\u81f4\u7684\uff0c\u6267\u884c\u547d\u4ee4 <code>yum install --assumeyes curl-devel<\/code> \u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<h5>\u9519\u8bef 3 - FATAL ERROR: EXPAT.H: NO SUCH FILE OR DIRECTORY<\/h5>\n<pre><code class=\"language-shell\">... \u7701\u7565\u90e8\u5206\u4fe1\u606f\nhttp-push.c:22:19: fatal error: expat.h: No such file or directory\n #include &lt;expat.h&gt;\n                   ^\ncompilation terminated.\nmake: *** [http-push.o] Error 1\n123456<\/code><\/pre>\n<p>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u67e5\u770b\u4e0e expat \u76f8\u5173\u7684\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-shell\"># rpm --query --all | grep expat\nexpat-2.1.0-10.el7_3.x86_64\n12<\/code><\/pre>\n<p>\u8fd9\u662f\u7f3a\u5c11 expat-devel \u5bfc\u81f4\u7684\uff0c\u6267\u884c\u547d\u4ee4 <code>yum install --assumeyes expat-devel<\/code> \u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<h3>7\u3001\u5f53Git\u6e90\u7801\u7f16\u8bd1\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u6267\u884c\u5b89\u88c5\u64cd\u4f5c<\/h3>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git-2.17.1]# make prefix=\/usr\/local\/git install<\/code><\/pre>\n<h3>8\u3001\u5b89\u88c5\u5b8cGit \u670d\u52a1\u540e\uff0c\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<pre><code class=\"language-shell\">vim \/etc\/profile<\/code><\/pre>\n<p>\u6dfb\u52a0\u5982\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<pre><code class=\"language-shell\">export GIT_HOME=\/usr\/local\/git\nexport PATH=$PATH:${GIT_HOME}\/bin<\/code><\/pre>\n<p><img src=\"C:\\Users\\Administrator\\AppData\\Roaming\\Typora\\typora-user-images\\image-20210914195925581.png\" alt=\"image-20210914195925581\" \/><\/p>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u91cd\u8f7d\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-shell\">source \/etc\/profile<\/code><\/pre>\n<h3>9\u3001\u9a8c\u8bc1Git \u7248\u672c\u53f7<\/h3>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git-2.17.1]# git --version\ngit version 2.17.1<\/code><\/pre>\n<h3>10\u3001\u5c06git\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u8def\u5f84\uff0c\u4e0d\u7136\u540e\u9762\u514b\u9686\u65f6\u4f1a\u62a5\u9519<\/h3>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git-2.17.1]# ln -s \/usr\/local\/git\/bin\/git-upload-pack \/usr\/bin\/git-upload-pack\n[root@iZbp159egvvktszc82dr5xZ git-2.17.1]# ln -s \/usr\/local\/git\/bin\/git-recive-pack \/usr\/bin\/git-recive-pack<\/code><\/pre>\n<p>\u81f3\u6b64\uff0cGit\u5c31\u5b89\u88c5\u5b8c\u6210\u3002<\/p>\n<h3>11\u3001\u521b\u5efa\u4e00\u4e2agit\u7528\u6237\u7ec4\u548c\u7528\u6237\uff0c\u7528\u6765\u8fd0\u884cgit\u670d\u52a1<\/h3>\n<pre><code class=\"language-shell\"># groupadd git\n# useradd git -g git\n# passwd git  #\u53c2\u6570\u662f\u7528\u6237\u540d\n# su - git  \/\/\u5207\u6362git\u7528\u6237<\/code><\/pre>\n<p>\u3010\u6ce8\u3011\u6700\u597d\u5207\u6362\u5230git\u7528\u6237 \u4e0d\u7136\u540e\u9762\u65b0\u5efa\u7684git\u4ed3\u5e93\u90fd\u8981\u6539\u6743\u9650<\/p>\n<h3>11\u3001\u521b\u5efa\u8bc1\u4e66\u767b\u5f55<\/h3>\n<p>\u5728Git\u670d\u52a1\u5668\u4e0a\u9996\u5148\u9700\u8981\u5c06\/etc\/ssh\/sshd_config\u4e2d\u5c06RSA\u8ba4\u8bc1\u6253\u5f00<\/p>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git-2.17.1]# vim \/etc\/ssh\/sshd_config<\/code><\/pre>\n<p><img src=\"git\u670d\u52a1\u5668\u642d\u5efa.assets\/webp.webp\" alt=\"img\" \/><\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u516c\u94a5\u5b58\u653e\u5728 .ssh\/authorized_keys \u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u5728\/home\/git\u4e0b\u521b\u5efa.ssh\u76ee\u5f55\uff0c\u7136\u540e\u521b\u5efaauthorized_keys\u6587\u4ef6\uff0c\u5e76\u5c06\u521a\u751f\u6210\u7684\u516c\u94a5\u5bfc\u5165\u8fdb\u53bb\u3002<\/p>\n<pre><code class=\"language-shell\"># cd \/home\/git\/\n# mkdir .ssh #\u65b0\u5efa\u6587\u4ef6\u5939\n# chmod 700 .ssh \n# touch .ssh\/authorized_keys  #\u65b0\u5efa\u6587\u4ef6\n# chmod 600 .ssh\/authorized_keys<\/code><\/pre>\n<pre><code class=\"language-shell\">[root@iZbp159egvvktszc82dr5xZ git]# ls -al\ntotal 36\ndrwx------  4 git  git  4096 Sep  6 14:50 .\ndrwxr-xr-x. 4 root root 4096 Sep  6 13:46 ..\n-rw-------  1 git  git   611 Sep  7 08:56 .bash_history\n-rw-r--r--  1 git  git    18 Apr  1  2020 .bash_logout\n-rw-r--r--  1 git  git   193 Apr  1  2020 .bash_profile\n-rw-r--r--  1 git  git   231 Apr  1  2020 .bashrc\ndrwxrwxr-x  4 git  git  4096 Sep  6 14:30 data\ndrwx------  2 git  git  4096 Sep  6 14:50 .ssh\n-rw-------  1 git  git   889 Sep  6 14:50 .viminfo<\/code><\/pre>\n<h3>12\u3001\u5c06\u5ba2\u6237\u7aef\u516c\u94a5\u5199\u5165\u5230authorized_keys\u6587\u4ef6\u4e2d<\/h3>\n<h4>12.1\u751f\u6210\u516c\u94a5<\/h4>\n<h4>12.2\u5199\u5165\u670d\u52a1\u5668<\/h4>\n<p>windows\u9ed8\u8ba4\u751f\u6210\u5728C:\\Users\\Administrator.ssh\u6587\u4ef6\u5939\u4e2d\uff0c\u5c06id_rsa.pub\u6587\u4ef6\u5185\u5bb9vim authorized_keys,\u4fdd\u5b58\u9000\u51fa<\/p>\n<p>\u6b64\u65f6\uff0c\u4f7f\u7528windows\u7ec8\u7aef\uff0c\u5373\u53ef\u7528SSH\u76f4\u8fde\u670d\u52a1\u5668<\/p>\n<p><img src=\"git\u670d\u52a1\u5668\u642d\u5efa.assets\/image-20210915025412465.png\" alt=\"image-20210915025412465\" \/><\/p>\n<h3>13\u3001\u521b\u5efa\u88f8\u4ed3\u5e93<\/h3>\n<p>\u5b8c\u6210\u4ee5\u4e0a\u64cd\u4f5c\u540e\uff0c\u5728\u670d\u52a1\u7aef\u521b\u5efagit\u4ed3\u5e93\u7684\u76ee\u5f55\uff1a<\/p>\n<pre><code class=\"language-shell\">[root@localhost ~]# mkdir \/data\/gitroot\n[root@localhost ~]# cd \/data\/gitroot\n[root@localhost \/data\/gitroot]#\n[root@localhost \/data\/gitroot]# git init --bare sample.git\nInitialized empty Git repository in \/data\/gitroot\/sample.git\/\n##\u521d\u59cb\u5316\u7a7a\u7684 Git \u7248\u672c\u5e93\u4e8e \/data\/gitroot\/sample.git\/\n[root@localhost \/data\/gitroot]# ls\nsample.git\n[root@localhost \/data\/gitroot]# chown -R git.git sample.git<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001 \u9996\u5148\u68c0\u67e5\u7535\u8111\u662f\u5426\u5df2\u5b89\u88c5git\u8fdc\u7a0b\u670d\u52a1\uff0c\u5982\u6ca1\u6709Git\u670d\u52a1\u8bf7\u6267\u884c\u7b2c\u4e09\u6b65 rpm -qa git 2\u3001 \u5982\u679c\u6267\u884c\u5b8c\u7b2c\u4e00\u6b65\u53d1\u73b0\u7cfb\u7edf\u5b89\u88c5\u4e86g   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[25],"tags":[8],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/101"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=101"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":102,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions\/102"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}