我需要创建一个我的Git项目的存档,忽略并省略指定的文件.gitignore,但包括实际的.git存储库文件夹.只需运行git archive master就会遗漏.git文件夹.
有没有办法让git archive包含.git文件夹但仍然忽略指定的文件.gitignore?
由于git archive只生成tar存档,您可以tar直接使用该文件.
$ git archive HEAD > tar.tar
$ tar -rf tar.tar .git
Run Code Online (Sandbox Code Playgroud)
tar的-r选项将给予正在处理的存档的文件(后面指定-f)附加.查看tar的手册页,了解tar所具有的令人生畏的功能列表.
看起来像做类似的事情
# copy over all project files except for those ignored
git clone /path/to/repository /path/to/output
# create a tar.gz archive of the project location
tar czvf projectExport.tar.gz /path/to/output
# remove the cloned directory
rm -fr /path/to/output
Run Code Online (Sandbox Code Playgroud)
完成工作。这不是世界上最漂亮的解决方案,但看起来很有效。