我正在尝试按照Windows上的本指南进行远程推送,以将其部署到Windows服务器上。
https://ma.ttias.be/simple-git-push-workflow-deploy-code-server/
从笔记本电脑上的git服务器克隆回购
向我的服务器添加了一个远程位置。
$ git remote add live \\\\hostname\\E\\myapp\\.git
git config看起来像这样:
[remote "live"]
url = \\\\hostname\\E\\myapp\\.git
fetch = +refs/heads/*:refs/remotes/live/*
cd \e
mkdir myapp
mkdir .git
cd .git
git init --bare
git clone /e/.git /e/myapp
#!/bin/sh
git --work-tree=E:\\myapp --git-dir=E:\\myapp\\.git checkout -f
git --work-tree=E:\\myapp --git-dir=E:\\myapp\\.git pull
echo "Hooray, the new version is published!"
exit 0
测试1:git push live master
Enumerating objects: 201, done.
Counting objects: 100% (201/201), done.
Delta compression using up to 4 threads
Compressing objects: 100% (198/198), done.
Writing objects: 100% (201/201), 86.90 KiB | 7.00 KiB/s, done.
Total 201 (delta 117), reused 0 (delta 0)
remote: Resolving deltas: 100% (117/117), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
我运行了以下命令
git config receive.denyCurrentBranch updateInstead
测试2:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To \\patlbearing02\E\bot-live\.git
! [remote rejected] master -> master (Working directory has staged changes)
我现在被困在这个位置,不确定什么地方出了问题。我是git的新手,我尝试了很多搜索,但还没有走运。
答案 0 :(得分:1)
我在朋友的帮助下找到了解决方案。
服务器端更改
错误1。
我做的一个大错误是,我对克隆的理解是错误的。克隆会克隆存储库并保持连接。我不得不像上面那样将主仓库用作远程仓库,而不是克隆仓库。我不得不更改克隆代码(不必这样做,但在根目录上使用.git是一个不好的选择,我打算删除认为以为复制到myapp后没有用,但我错了),并且还添加了远程代码笔记本电脑。
我在服务器上删除了myapp和.git。然后我更改了步骤3。如下所示
旧:
cd \e
mkdir myapp
mkdir .git
cd .git
git init --bare
git clone /e/.git /e/myapp
新功能:
cd \e
mkdir myapp
mkdir myapp.git
cd myapp.git
git init --bare
git clone /e/myapp.git /e/myapp
错误2。
接收后挂钩需要完整的UNC,它可以远程运行,但不能识别本地路径。我不确定为什么,也许是特定于Windows的。很想知道专家的回答。
所以我没有将4更改为
旧:
#!/bin/sh
git --work-tree=E:\\myapp --git-dir=E:\\myapp\\.git checkout -f
git --work-tree=E:\\myapp --git-dir=E:\\myapp\\.git pull
echo "Hooray, the new version is published!"
exit 0
新功能:
#!/bin/sh
git --work-tree=\\\\hostname\\e\\myapp --git-dir=\\\\hostname\\e\\myapp.git checkout -f #notice I am pointing to myapp.git not myapp\\.git (it is there but its cloned we need to use main bare repo here)
git --work-tree=\\\\hostname\\e\\myapp --git-dir=\\\\hostname\\e\\myapp.git pull
echo "Hooray, the new version is published!"
exit 0
在笔记本电脑/开发机方面:
我正在添加克隆的git存储库,相反,我应该使用主存储库。
旧
$ git remote add live \\\\hostname\\E\\myapp\\.git
新功能:
$ git remote add live \\\\hostname\\E\\myapp.git #notice I am pointing to myapp.git not myapp\\.git (it is there but its cloned we need to use main bare repo here)
测试:git push live master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 280 bytes | 93.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Checking connectivity: 3, done.
remote: There is no tracking information for the current branch.
remote: Please specify which branch you want to merge with.
remote: See git-pull(1) for details.
remote:
remote: git pull <remote> <branch>
remote:
remote: If you wish to set tracking information for this branch you can do so with:
remote:
remote: git branch --set-upstream-to=<remote>/<branch> master
remote:
remote: Hooray, the new version is published!
To \\hostname\E\myapp.git
1460906..1ec756d master -> master