【问题标题】:Git Pull from Shell scriptGit 从 Shell 脚本中拉取
【发布时间】:2014-07-08 16:37:42
【问题描述】:

我正在尝试从 bash 脚本更新 git repo,但遇到了一些麻烦。如果 git pull 之后没有其他行或字符,我可以运行 git pull 并让它工作,但如果我说有

#!/bin/bash
git pull
echo "test"

然后我得到

' is not a git command. See 'git --help'.

Did you mean this?
        pull

在终端中而不是它实际执行git pull

【问题讨论】:

  • 那个文件有 DOS 换行符吗?在该脚本上运行 dos2unix 有帮助吗?
  • 如果您有基于 UNIX 的系统,请使用 apt-get install git,如果您有基于窗口的系统,请手动安装 git。
  • 正如@EtanReisner 建议的那样,您实际上正在运行git pull\r
  • @Ioan 他们显然安装了 git,因为他们从 git 收到错误消息。

标签: git bash shell


【解决方案1】:

你必须首先像 Etan 提到的那样做 dos2unix 。如果我执行相反的操作(即 unix2dos),我可以重新生成相同的错误

$ cat 1.sh

#!/bin/bash

git pull
echo ----

$ ./1.sh

fatal: Not a git repository (or any parent up to mount parent /cygdrive)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
----

见上文,git pull 命令有效,但有一条有效的错误消息,在我第一次做的 pull 之后没有提到 repo。这意味着 git 存在(如果你这样做 which git 你会看到有效的 git 可执行位置)。

$ unix2dos.exe ./1.sh

unix2dos: converting file ./1.sh to DOS format ...

现在,我的文件是 DOS 格式(我在 Linux 机器上运行脚本)。你在用 Cygwin 吗?

$ ./1.sh

./1.sh: line 2: $'\r': command not found
' is not a git command. See 'git --help'.

Did you mean this?
        pull
----

好的,使用 dos2unix 将其转换回 Unix 行结束字符

$ dos2unix.exe ./1.sh

dos2unix: converting file ./1.sh to Unix format ...

$ ./1.sh

fatal: Not a git repository (or any parent up to mount parent /cygdrive)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
----

它按预期工作。

或尝试使用 bash -x

运行

【讨论】:

    猜你喜欢
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    相关资源
    最近更新 更多