我需要创建我的Git项目的存档,忽略并忽略由.gitignore
指定的文件,但包括实际的.git
存储库文件夹。只需运行git archive master
即可省略.git
文件夹。包含实际存储库的Git存档?
有没有办法使git archive
包括.git
文件夹,但仍忽略由.gitignore
指定的文件?
我需要创建我的Git项目的存档,忽略并忽略由.gitignore
指定的文件,但包括实际的.git
存储库文件夹。只需运行git archive master
即可省略.git
文件夹。包含实际存储库的Git存档?
有没有办法使git archive
包括.git
文件夹,但仍忽略由.gitignore
指定的文件?
看起来像做这样的事情
# 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
能够完成任务。这不是世界上最美丽的解决方案,但它看起来像是有效的。
这不考虑.gitignore。 – djanowski 2017-03-30 19:41:09
由于git archive
只是产生一个tar归档文件,你可以直接使用tar
来处理那个文件。
$ git archive HEAD > tar.tar
$ tar -rf tar.tar .git
焦油的-r
选项追加给予归档的文件进行比较(-f
后指定)正在制定。检查焦油的手册页,了解焦油具有的令人恐惧的功能列表。
这应该是被接受的答案,因为它考虑到.gitignore。 – djanowski 2017-03-30 19:41:32
您可以单独复制'.git'文件夹,然后检出HEAD以获取文件。或者您只需将其作为远程存储库从其中提取即可。 – poke 2012-07-23 23:02:01