【问题标题】:Git push to remote "No such file or directory"Git推送到远程“没有这样的文件或目录”
【发布时间】:2017-02-17 21:34:57
【问题描述】:

我正在尝试将更改从本地计算机推送到实时服务器。我按照this page 上的步骤操作。

在我的本地机器上,这是我运行时得到的结果:$ git push web

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 291 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: /bin/bash: GIT_WORK_TREE=/var/www/html git checkout -f: No such file or directory
To ssh://MyDomainRemoved.com/var/git/myproject.git
   d8a9173..7903ea9  master -> master

实时服务器上,新的提交显示在$ git logpost-receive 钩子有问题。下面是 post-receive 文件现在的样子:

#!/bin/bash GIT_WORK_TREE=/var/www/html git checkout -f

我已经从我读过的其他线程中尝试过一些事情:

  • 试过#!/bin/bash#!/bin/sh
  • 删除了#!/bin/bash 行上的隐藏回车符。这允许 bash 在没有打开错误的情况下运行,但仍然没有此类文件错误。
  • /var/www/ 更改为用户 www-data
  • CHMOD /var/www/777(还是没有这样的文件错误)

服务器是 Ubuntu 16.04。

还有什么想法可以尝试吗?

【问题讨论】:

  • 请包含git remote -v的输出
  • @orvi 当然可以:$ git remote -vorigin ssh://git@bitbucket.org/myusername/myproject.git (fetch) origin ssh://git@bitbucket.org/myusername/myproject.git (push) web ssh://root@MyDomainRemoved.com/var/git/myproject.git (fetch) web ssh://root@MyDomainRemoved.com/var/git/myproject.git (push)
  • 你的post-recive文件在哪里?
  • @orvi 在 /var/git/myproject.git/hooks
  • 好的。现在像这样编辑post-recieve文件#!/bin/bashexport GIT_DIR=/var/git/myproject/.git/export GIT_WORK_TREE=/var/git/myproject/cd /var/git.myproject/git fetchgit fetchgit merge origin/mastergit submodule update --init --recursive

标签: linux git bash ubuntu


【解决方案1】:

确保您的脚本分多行而不是一行:

#!/bin/bash 
GIT_WORK_TREE=/var/www/html git checkout -f

完整的命令是:

git --work-tree=/var/www/html --git-dir=/var/git/myproject/.git checkout -f

【讨论】:

  • 这行得通。谢谢@VonC!最终代码和你的一样,但在/myproject/.git 中没有/
猜你喜欢
  • 2018-03-10
  • 2019-12-13
  • 1970-01-01
  • 2016-05-31
  • 2021-05-01
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多