忽略.git,.gitignore等文件时如何执行gsutil cp -R?

问题描述 投票:9回答:2

我正在尝试自动将网络资产与Google云存储同步。我基本上需要将开发目录中的所有内容复制到云中。但是,我需要忽略.git目录和其他一些不相关的文件。

我不能只是执行'gsutil cp -R。 ',因为这绝对需要所有内容,包括.git。我试过'find。| fgrep git | gsutil cp -I',但是将所有目录展平并放在根目录中!

有没有一种方法可以用gsutil解决,或者我必须在脚本中执行一个循环,该循环使用-R上传所有目录(.git除外),然后上传当前目录中的单个文件?

google-cloud-platform gsutil
2个回答
3
投票

您有两个选择:

A)上传git文件后,将其删除:

gsutil rm gs://bucket/\*.git\*

B)使用find排除git文件:

find . -not -path '*/.git' -type f -printf '%P\n' | xargs -I '{}' gsutil cp '{}' gs://bucket/'{}'

来源:https://groups.google.com/forum/#!topic/gsutil-discuss/zoHhkTPhiNc

如果gsutil实现rsync会容易得多,但使用--exclude标志会更容易。


26
投票

您可以使用类似的命令:

gsutil rsync -x '\.git.*' dev_dir gs://your-bucket

请参阅Google Storage-rsync - Synchronize content of two buckets/directories

© www.soinside.com 2019 - 2024. All rights reserved.