【发布时间】:2021-09-13 05:26:15
【问题描述】:
我在 linux 服务器上有一个克隆目录。已配置密钥访问。在服务器上进行一些处理后,在输出端,我得到了需要添加到 git 的 csv 文件。我还需要在服务器上接收 git 本身已更改的文件(这些文件可以是新添加的文件,也可以是代码中的一些更改)。添加过程每天都在发生,所以我想自动化它。在其中一个网站上,我找到了一个适合我的示例。向服务器添加和克隆更改的两个脚本。启动自动化通过 crontab 进行。
代码文件:
#!/bin/bash
# Go to the GIT category
cd '/home/user/www/'
# Submitting changes to the main branch
git checkout main
git add -A
git commit -m "update main"
git push
还有……
#!/bin/bash
# Go to the GIT category
cd '/home/user/www/'
# Loading data from the main branch
git checkout main
git pull
但我在输出中收到以下错误,可能是什么问题?
Cronlog:
/home/user/RFFI-V/Work/start_git_download.sh: line 3: cd: too many arguments
/home/user/RFFI-V/Work/start_git_push.sh: line 3: cd: too many arguments
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
【问题讨论】:
-
如果你只是在目标机器上运行
cd '/home/user/www/'命令呢? (以root身份运行,crontab以root身份运行...) -
错误消息
cd: too many arguments似乎与问题中显示的脚本不匹配。您是否复制并粘贴了您实际使用的代码?对于调试,将第一行更改为#!/bin/bash -x并检查日志中的结果输出。 -
是 git init 丢失还是你正在克隆这个目录?
-
如图所示,我认为这些应该可以工作。我不得不说这很像 Windows 风格的换行符。你的脚本有可能是 CRLF 吗?如果是这样,bash 不兼容,转换为 Unix 风格的 LF。
-
不要这样做。使用 git 存储非人为生成的内容确实不是一个好主意,无论它多么普遍。