[英]How to extract all files of any commit to a folder/archive from a Git Repository?
I have a Git Repository. 我有一个Git存储库。 I want to export all files and folders from my repository history, based on the different commits, into a folder.
我想基于不同的提交将存储库历史记录中的所有文件和文件夹导出到一个文件夹中。 But I want to export all commits and branches separately.
但是我想分别导出所有提交和分支。 A sort of backup/archive for my git repository.
我的git存储库的一种备份/存档。
For example if I have a repository history of: 例如,如果我的存储库历史记录为:
-v2.0 My Latest commit -v1.0 My Initial commit -v2.0我的最新提交-v1.0我的初次提交
I want to export all files and folders of these different commits into separate folders. 我想将这些不同提交的所有文件和文件夹导出到单独的文件夹中。 I want the files as normal complete files not as a difference patch.
我希望这些文件作为普通的完整文件而不是作为差异补丁。
For example the folders "/MyGitBackup/Master/v1.0" and "/MyGitBackup/Master/v2.0" which should include the files of the according commits. 例如,文件夹“ /MyGitBackup/Master/v1.0”和“ /MyGitBackup/Master/v2.0”应包含相应提交的文件。
How can I achieve this? 我该如何实现? Is a GUI tool capable of this or something similar?
GUI工具是否具有此功能或类似功能? I use a Windows machine.
我使用Windows机器。
You can use git worktree <path> <commit>
that enables to checkout different commits to different directories. 您可以使用
git worktree <path> <commit>
来签出对不同目录的不同提交。 So, execute the following commands in your working directory: 因此,在您的工作目录中执行以下命令:
git worktree add /MyGitBackup/Master/v1.0 <v1.0 commit hash or tag>
git worktree add /MyGitBackup/Master/v2.0 <v2.0 commit hash or tag>
That sounds like a waste of space. 听起来像是在浪费空间。 But sure it's possible:
但请确保有可能:
git rev-list
command git rev-list
命令 git archive revision
with the appropriate flags git archive revision
This is one way to export the content of each revision in master
to a separate folder in a sub-directory of archive/
: 这是将
master
中每个修订的内容导出到archive/
子目录中单独文件夹中的一种方法:
git rev-list master | while read rev; do
echo creating archive for $rev
mkdir -p archive/$rev
git archive $rev | (cd archive/$rev; tar x)
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.