dzÎöwindowsÍâµØ´î½¨gitЧÀÍÆ÷µÄÒªÁì
Ëæ×ÅgitµÄÊ¢ÐУ¬Ô½À´Ô½¶àµÄ¹«Ë¾ºÍСÎÒ˽ÈË×îÏÈʹÓÃgit¾ÙÐа汾¿ØÖÆ¡£ËäÈ»ÓÐÐí¶àÔÚÏßµÄgitÍйÜЧÀÍÈçgithub¡¢gitlabºÍbitbucket£¬¿ÉÊǹØÓÚһЩ¿ª·¢ÕßÀ´Ëµ£¬ÔÚÍâµØ´î½¨gitЧÀÍÆ÷ÊǺÜÊÇÓÐÐëÒªµÄ¡£±¾Îľͽ«ÏÈÈÝÔõÑùÔÚwindowsϵͳÉϴgitЧÀÍÆ÷¡£
×°ÖÃGit
Ê×ÏÈ£¬ÐèÒªÔÚWindowsϵͳÉÏ×°ÖÃGitÈí¼þ¡£¿ÉÒÔ´ÓGit¹Ù·½ÍøÕ¾ÉÏÏÂÔØ×îеÄGit×°Öðü£¬²¢Æ¾Ö¤Ö¸Ê¾¾ÙÐÐ×°Öá£×°ÖÃÀú³ÌÖпÉÒÔÑ¡ÔñĬÈÏÉèÖ㬲»ÐèÒª¾ÙÐÐÈκÎÐ޸ġ£
½¨ÉèGit¿ÍÕ»
×°ÖÃÍêGitÖ®ºó£¬ÐèÒªÔÚÍâµØ½¨ÉèÒ»¸öGit¿ÍÕ»¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸ö¿ÍÕ»£º
$ git init --bare /path/to/repo.git
µÇ¼ºó¸´ÖÆ
ÆäÖÐ /path/to/repo.git ÊÇGit¿ÍÕ»µÄ´æ´¢Â·¾¶¡£¿ÉÒÔƾ֤ÐèҪѡÔñÆäËûµÄ·¾¶¡£¸ÃÏÂÁî»á½¨ÉèÒ»¸öÂã¿ÍÕ»£¬ÓÃÓÚ´æ´¢´úÂëºÍ°æ±¾ÐÅÏ¢¡£
ÉèÖÃȨÏÞ
ÔڴGitЧÀÍÆ÷ʱ£¬ÐèҪעÖØȨÏÞµÄÉèÖ᣿ÉÒÔͨ¹ýÒÔÏ°취À´ÉèÖÃȨÏÞ£º
·¿ªGit¿ÍÕ»µÄÉèÖÃÎļþ config Îļþ£¬Â·¾¶Îª repo.git/config¡£
ÔÚ [core] ±êÇ©ÏÂÌí¼ÓÒÔÏ´úÂ룺
[receive] denyCurrentBranch = ignore
µÇ¼ºó¸´ÖÆ
¸ÃÉèÖõÄ×÷ÓÃÊÇ·¿ªÁ˶ÔÄ¿½ñ·ÖÖ§µÄдÈëȨÏÞ¡£ÓÉÓÚÔÚÍâµØ´î½¨µÄGitЧÀÍÆ÷ÉÏ£¬½öÓÐÖÎÀíÔ±»ò¾ßÓÐдÈëȨÏÞµÄÓû§²Å»ª¶Ô¿ÍÕ»¾ÙÐÐÐ޸ġ£
¿ªÆôSSHЧÀÍ
ÔÚWindowsϵͳÖУ¬ÐèҪʹÓÃSSHÐÒéÀ´¾ÙÐдúÂëµÄ´«Êä¡£Òò´ËÐèҪװÖÃOpenSSHÀ´¿ªÆôSSHЧÀÍ¡£¿ÉÒÔ´ÓOpenSSH¹ÙÍøÉÏÏÂÔØ×îеÄOpenSSH×°Öðü£¬²¢Æ¾Ö¤Ö¸Ê¾¾ÙÐÐ×°Öá£
ÉèÖÃSSHЧÀÍ
×°ÖÃÍêOpenSSHºó£¬ÐèÒªÉèÖÃSSHЧÀÍ¡£¿ÉÒÔͨ¹ýÒÔÏ°취À´ÉèÖãº
·¿ª OpenSSH ×°ÖÃĿ¼Ï嵀 etc\sshd_config Îļþ£¬Èç C:\Program Files\OpenSSH\etc\sshd_config¡£
ÔÚ×îºóÌí¼ÓÒÔÏÂÄÚÈÝ£º
Match User git ForceCommand C:\Program Files\Git\bin\git.exe serve --enforce-git-protocol --stateless-rpc "D:\git-shell-commands\git-receive-pack.exe 'D:\repos'"
µÇ¼ºó¸´ÖÆ
ÆäÖÐ git ΪÓû§Ãû£¬C:\Program Files\Git\bin\git.exe ΪGitÏÂÁîµÄ·¾¶£¬D:\git-shell-commands\git-receive-pack.exe ΪGitµÄÎüÊÕÏÂÁD:\repos ΪGit¿ÍÕ»µÄ´æ´¢Â·¾¶¡£Æ¾Ö¤×Ô¼ºµÄÏÖÕæÏàÐξÙÐÐÐ޸ļ´¿É¡£
Æô¶¯SSHЧÀÍ
ÉèÖÃÍêSSHЧÀÍÖ®ºó£¬ÐèÒªÆô¶¯Ð§ÀÍ¡£·¿ª Windows PowerShell ´°¿Ú£¬ÊäÈëÒÔÏÂÏÂÁî¾ÙÐÐЧÀ͵ÄÆô¶¯£º
Start-Service sshd
µÇ¼ºó¸´ÖÆ
Ñé֤ЧÀÍÊÇ·ñÆô¶¯Àֳɣ¬¿ÉÒÔÊäÈëÒÔÏÂÏÂÁ
Get-Service sshd
µÇ¼ºó¸´ÖÆ
ÈôÊÇÀÖ³ÉÆô¶¯£¬ÔòÊä³öµÄ״̬Ϊ Running¡£
ÅþÁ¬GitЧÀÍÆ÷
ÔڴºÃGitЧÀÍÆ÷ºó£¬ÐèÒª¾ÙÐÐÅþÁ¬²âÊÔ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´²âÊÔ£º
$ git clone ssh://git@localhost:/path/to/repo.git
µÇ¼ºó¸´ÖÆ
ÆäÖÐ git ΪÓû§Ãû£¬localhost ΪIPµØµã»òÓòÃû£¬/path/to/repo.git ΪGit¿ÍÕ»µÄ´æ´¢Â·¾¶¡£Æ¾Ö¤×Ô¼ºµÄÏÖÕæÏàÐξÙÐÐÐ޸ļ´¿É¡£
Ìí¼ÓGitÓû§
ÔÚGitЧÀÍÆ÷ÉÏ£¬ÐèÒªÌí¼ÓÓû§²Å»ª¾ÙÐдúÂëµÄÌá½»ºÍÖÎÀí¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Ìí¼ÓÓû§£º
$ adduser git
µÇ¼ºó¸´ÖÆ
ÊäÈëÃÜÂ벢ƾָ֤ʾ¾ÙÐвÙ×÷¼´¿É½¨ÉèÐÂÓû§¡£
ÉèÖÃSSH¹«Ô¿
ÔÚδÌí¼ÓSSH¹«Ô¿µÄÇéÐÎÏ£¬ÊÇÎÞ·¨ÔÚGitЧÀÍÆ÷ÉϾÙÐдúÂëÍйܵġ£Òò´ËÐèÒªÏÈÉèÖÃSSH¹«Ô¿¡£¿ÉÒÔͨ¹ýÒÔÏ°취À´ÉèÖãº
ÔÚ¿Í»§¶Ë»úеÉÏÌìÉúSSH¹«Ô¿ºÍ˽Կ¡£ÔÚ Windows PowerShell ´°¿ÚÖÐÊäÈëÒÔÏÂÏÂÁ
$ ssh-keygen -t rsa -C "your_email@example.com"
µÇ¼ºó¸´ÖÆ
½«ÌìÉúµÄ¹«Ô¿¸´ÖƵ½GitЧÀÍÆ÷É쵀 D:\git-shell-commands\authorized_keys ÎļþÖС£
Íê³ÉÍâµØGitЧÀÍÆ÷´î½¨
ÒÔÉϾÍÊÇÔÚWindowsϵͳÉϴGitÍâµØЧÀÍÆ÷µÄËùÓа취¡£Íê³Éºó£¬¼´¿ÉÔÚÍâµØ¾ÙÐдúÂëµÄÌá½»ºÍÖÎÀíÁË¡£GitµÄÂþÑÜʽ°æ±¾¿ØÖÆÌØÕ÷£¬ÉÁ¿ª·¢Àú³ÌÔ½·¢¸ßЧºÍ±ã½Ý¡£Ï£ÍûÕâƪÎÄÕÂÄܶÔÄãÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇdzÎöwindowsÍâµØ´î½¨gitЧÀÍÆ÷µÄÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡