【问题标题】:Git Remote Push Deploy Workflow on WindowsWindows 上的 Git 远程推送部署工作流程
【发布时间】:2020-03-26 22:53:32
【问题描述】:

我正在尝试按照 windows 上的本指南进行远程推送以部署到 windows 服务器上。

https://ma.ttias.be/simple-git-push-workflow-deploy-code-server/

  1. 从我笔记本电脑上的 git 服务器克隆 repo

  2. 向我的服务器添加了一个远程位置。

    $ git remote add live \\\\hostname\\E\\myapp\\.git

git 配置如下所示:

[remote "live"]
    url = \\\\hostname\\E\\myapp\\.git
    fetch = +refs/heads/*:refs/remotes/live/*
  1. 在应用服务器上创建了一个裸仓库。使用 git bash

    cd \e
    mkdir myapp
    mkdir .git
    cd .git
    git init --bare
    git clone /e/.git /e/myapp

  1. 在 e:\myapp.git\hooks 文件夹中添加了 post-receive

    #!/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

测试一: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 新手,我尝试了很多搜索,但还没有运气。

【问题讨论】:

    标签: git github


    【解决方案1】:

    在朋友的帮助下,我找到了解决方案。

    服务器端更改

    错误 1。

    我犯的一个大错误是,我对克隆的理解是错误的。克隆确实克隆了存储库并保持连接。就像我上面所做的那样,我必须将主仓库用作远程仓库,而不是克隆仓库。我不得不更改克隆的代码(不必更改,但在 root 上使用 .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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2014-05-04
      • 2014-09-11
      • 2015-05-16
      • 2012-10-12
      • 2019-06-16
      • 1970-01-01
      相关资源
      最近更新 更多