问题
I have a Git Repository. 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.
For example if I have a repository history of:
-v2.0 My Latest commit -v1.0 My Initial commit
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.
How can I achieve this? Is a GUI tool capable of this or something similar? I use a Windows machine.
回答1:
That sounds like a waste of space. But sure it's possible:
- For each revision, as per the
git rev-list
command - Run
git archive revision
with the appropriate flags
This is one way to export the content of each revision in master
to a separate folder in a sub-directory of 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
回答2:
You can use git worktree <path> <commit>
that enables to checkout different commits to different directories.
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>
来源:https://stackoverflow.com/questions/40811177/how-to-extract-all-files-of-any-commit-to-a-folder-archive-from-a-git-repository