0

我正在尝试将文件夹(.husky)从当前路径复制到父文件夹:

#!/bin/bash
# Get parent folder:
parent_folder=$(cd ../ && pwd)
# Trying to copy folder called `".husky"` into parent folder:
cp .husky $parent_folder/test1

但我收到错误消息:

fatal: not a git repository (or any of the parent directories): .git

截屏:

在此处输入图像描述

4

1 回答 1

1

关于父文件夹,首先跟踪脚本的当前文件夹,假设 .. 相对于脚本所在的位置:

DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
parent_folder=$(cd "${DIR}" && pwd)
echo "parent_folder='${parent_folder}'"

然后添加set -x脚本的第一行以查看它触发“ not a git repository”错误消息的位置。


OP kittu在评论中确认:

实际上我之前有git别名设置 where cpis alias cp='git commit -p',因此出现git错误。
它现在工作正常。

于 2021-05-07T06:16:46.783 回答