如何在忽略.git,.gitignore等文件的情况下执行gsutil cp -R?

Sha*_*baz 9 gsutil google-cloud-platform

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

我不能只做'gsutil cp -R.'因为这绝对是一切,包括.git.我试过'find.| fgrep git | gsutil cp -I',但这会使所有目录变平并将它们放在root中!

有没有办法可以用gsutil来解决这个问题,还是我必须在脚本中循环,用-R上传所有目录(.git除外),然后在当前目录中上传单个文件?

Mik*_*rtz 25

您可以使用如下命令:

gsutil rsync -x '\.git.*' dev_dir gs://your-bucket
Run Code Online (Sandbox Code Playgroud)

  • 这是一个合适的答案。不知道为什么它被否决了。 (2认同)

Azi*_*leh 6

您有两个选择:

A) 上传后删除 git 文件:

gsutil rm gs://bucket/\*.git\*
Run Code Online (Sandbox Code Playgroud)

B) 使用 find 排除 git 文件:

find . -not -path '*/.git' -type f -printf '%P\n' | xargs -I '{}' gsutil cp '{}' gs://bucket/'{}'
Run Code Online (Sandbox Code Playgroud)

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

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