簡體   English   中英

在Windows 2012上設置和訪問git

[英]Setting up and accessing git on windows 2012

我正在使用以下計算機。

本地計算機:Windows10。我在這里也有Windows 7計算機,但實際上並沒有使用它們。

Windows Server 2012 r2(不在同一物理位置)。 這不是生產服務器,它只是我用來托管各種腳本的服務器。

我目前僅使用IP地址訪問Windows服務器。 但是,如果通過某種方式使此操作更容易,我可以為其分配一個靜態IP鏈接到子域。

顯然是使用服務器的真實IP,但出於本文的目的,我使用的是1.1.1.1

我已經在Windows服務器上設置了git。 我遵循了: https : //www.server-world.info/en/note?os=Windows_Server_2012&p=openssh

我只是刪除了我正在測試的所有存儲庫,所以我可以在這里逐步進行操作,希望有人可以指出我出了問題的地方。

我在服務器上創建了一個名為“ kannkor”的用戶,並為其分配了密碼。

我目前正在RDC(遠程桌面連接)進入服務器。 因此,我可以做任何事情,如果需要,可以從那里進行驗證。

我已打開膩子,連接類型為“ ssh”,主機名是服務器IP,位於端口22上。它問我:

login as: 

我輸入“ kannkor”,然后詢問:

kannkor@1.1.1.1's password: 

我輸入。它帶我去:

kannkor@computername C:\Users\kannkor>

我希望存儲庫位於d驅動器上。 我可以更改目錄:

我創建一個新文件夾:

d:
mkdir repos
cd repos

從RDC,我可以驗證repos文件夾現在已在D下創建:仔細檢查清單,這意味着已設置該驅動器/文件夾的用戶名/密碼/權限。

在這個階段,我感覺我已經遵循了100個演練,但最終都一樣。 因此,為了爭辯,我將遵循以下內容: http : //thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push /

在本地計算機上,我打開git bash並輸入:

ssh kannkor@1.1.1.1

它要求我輸入密碼,然后輸入。

我將執行以下操作(在演練之后)。

d:
cd repos

我現在在:

D:\repos>

通過更改驅動器/目錄,也許這是我出了問題的地方...但是,一定有可能..繼續本演練

mkdir my_project.git
cd my_project.git
git init --bare
-> Initialized empty Git repository in D:/repos/my_project.git/

我做了git update-server-info(我嘗試過,不管有沒有,對最終錯誤都沒有影響)。

在RDC上,我可以看到它創建了文件夾my_project.git,並且其中包含一些文件/文件夾,掛鈎,信息,對象等。不要觸摸它,只需注意它即可。

到本地機器上

我輸入exit,退出ssh

和以前一樣,我希望將它們保存在d驅動器上。 為避免混淆,我將調用父目錄存儲庫。

我當前在:/ d /存儲庫

mkdir my_project
cd my_project
git init
-> Initialized empty Git repository in D:/repositories/my_project/.git/
(changed git add * to git add --all)
git add --all
git commit -m "my initial commit message"
>On branch master

Initial commit

nothing to commit

git remote add origin kannkor@1.1.1.1:d/repos/my_project.git
git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'kannkor@1.1.1.1:d/repos/my_project.git'

我相信這是因為最初的提交沒有任何內容。 仍在本地計算機上,我導航至:d:\\ repositories \\ my_project \\

我創建一個文件:placeholder.txt,並添加一行文本,然后將其保存。

返回git bash

git add --all

git commit -m "my initial commit message"
[master (root-commit) ac54490] my initial commit message
 1 file changed, 1 insertion(+)
 create mode 100644 placeholder.txt

對於本地提交要好得多。 我再試一次。

git push -u origin master
kannkor@1.1.1.1's password:
fatal: ''d/repos/my_project.git'' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

這是關於我被卡住的地方。 我的假設是這一行:

git remote add origin kannkor@1.1.1.1:d/repos/my_project.git

我嘗試了多種方法,包括:

git remote add origin kannkor@1.1.1.1:d:/repos/my_project.git

用\\代替/。 在其末尾添加斜杠。

我嘗試過的其他各種嘗試都失敗了。

fatal: ''D:\repos\my_project.git'' does not appear to be a git repository
fatal: ''D:/repos/my_project.git'' does not appear to be a git repository

我也嘗試過使用scp:

https://stackoverflow.com/a/20987150

最終結果相同。

任何意見,將不勝感激。

d/repos/my_project.git看起來不像有效路徑。

/d/repos/my_project.git會的。

嘗試:

git remote set-url origin kannkor@1.1.1.1:/d/repos/my_project.git
git push -u origin master

初步介紹,但我相信我有答案(解決)。

https://github.com/PowerShell/Win32-OpenSSH/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-Win32_OpenSSH

簡而言之,存在一個已知的錯誤 (自2017年以來),該錯誤是當服務器的默認外殼使用cmd.exe時,它不使用單引號。 這就是為什么錯誤會返回看起來奇怪的雙單引號的原因。

fatal: ''D:\repos\my_project.git'' does not appear to be a git repository

解決方法是將服務器的默認外殼從cmd.exe更改為powershell。 有關執行此操作的詳細信息,請參見此處

我正在復制/粘貼上面的鏈接,以防萬一該鏈接失效。

在配置DefaultShell之前,請確保滿足以下先決條件

OpenSSH安裝路徑在系統PATH中。 如果尚不存在,請修改系統PATH並重新啟動sshd服務。

跟着這些步驟:

在服務器端,在Windows注冊表中配置默認​​的ssh shell。 Computer \\ HKEY_LOCAL_MACHINE \\ SOFTWARE \\ OpenSSH \\ DefaultShell-Shell可執行文件的完整路徑

Computer \\ HKEY_LOCAL_MACHINE \\ SOFTWARE \\ OpenSSH \\ DefaultShellCommandOption(可選)-切換配置的默認外殼程序執行命令所需的開關,立即退出並返回到調用過程。 默認情況下,它是-c。

Powershell cmdlet將Powershell Bash設置為默認Shell

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force  
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value  "/c" -PropertyType String -Force

為了確認您已正確完成上述操作,在ssh進入服務器時,應使用Powershell,而不是cmd提示符。

最后,命令的正確語法確實是這樣的:

kannkor@1.1.1.1:D:/repos/my_project.git

總而言之。

git remote add origin kannkor@1.1.1.1:D:/repos/my_project.git
git push origin master
kannkor@1.1.1.1's password:
Everything up-to-date

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM