Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 在Bash脚本中使用ignore压缩_Git_Bash_Zip - Fatal编程技术网

Git 在Bash脚本中使用ignore压缩

Git 在Bash脚本中使用ignore压缩,git,bash,zip,Git,Bash,Zip,找到一个我必须用于压缩托管目录的压缩包,忽略诸如bower\u组件、.git和node\u模块等文件: #!/bin/bash # This script zips a directory, excluding specified files, types and subdirectories. # while zipping the directory it excludes hidden directories and certain file types [[ "`/usr/bin/t

找到一个我必须用于压缩托管目录的压缩包,忽略诸如
bower\u组件
.git
node\u模块等文件

#!/bin/bash
# This script zips a directory, excluding specified files, types and subdirectories.
#  while zipping the directory it excludes hidden directories and certain file types

[[ "`/usr/bin/tty`" == "not a tty" ]] && . ~/.bash_profile

DIRECTORY=$(cd `dirname $0` && pwd)

if [[ -z $1 ]]; then
  echo "Usage: managed_directory_compressor /your-directory/ zip-file-name"
else
  DIRECTORY_TO_COMPRESS=$1
  ZIPPED_FILE="$2.zip"
  COMPRESS_IGNORE_DIR=("\.git" "node_modules" "bower_components")

  IGNORE_LIST=("*/\.*" "\.* "\/\.*"")
  if [[ -n $COMPRESS_IGNORE_DIR ]]; then
      for IGNORE_DIR in "${COMPRESS_IGNORE_DIR[@]}"; do
          IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/***")  ## "$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/*"  perhaps is enough?
      done
  fi

  zip -r "$ZIPPED_FILE" "$DIRECTORY_TO_COMPRESS" -x "${IGNORE_LIST[@]}" # >/dev/null
  echo zip -r "$ZIPPED_FILE" "$DIRECTORY_TO_COMPRESS" -x "${IGNORE_LIST[@]}" # >/dev/null
  echo "Done"
fi
唯一的问题是,我想忽略的目录仍在创建中,只是空的

有什么建议吗?

zip手册页上说

请注意,当前目录需要尾随/字符(如中所示)

包括目录目录(dir)

因此,类似地,排除似乎也起作用:将脚本中的标记行替换为

IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/")
我们应该做到这一点

(我的zip是Ubuntu Linux上的3.0版)

IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/")