Here is a tutorial that explains how to copy a folder from a specific commit in a Git repository to a local directory using the
git archive and
- Navigate to the parent directory of the destination directory:
- Create the destination directory where you want to copy the files:
- Check out the desired commit:
git checkout <commit_hash>
<commit_hash> with the hash of the commit that contains the folder you want to copy. You can find the commit hash using
- Use the
git archivecommand to create a tar archive of the desired folder:
git archive <commit_hash> <folder_path> | tar -x -C destination_directory
<commit_hash> with the hash of the commit that contains the folder you want to copy. Replace
<folder_path> with the path to the folder you want to copy, relative to the root of the Git repository. The
git archive command creates a tar archive of the specified folder in the specified commit.
tar -x -C destination_directory command extracts the contents of the tar archive to the
- Optionally, move the files from the extracted directory to the desired location:
mv destination_directory/<folder_name> /path/to/new/location
<folder_name> with the name of the extracted directory. Replace
/path/to/new/location with the path to the desired location for the copied files.
- Check out the original branch or commit:
git checkout <original_branch_or_commit>
<original_branch_or_commit> with the name or hash of the original branch or commit.
- (Optional) Remove the temporary destination directory:
rm -r destination_directory
This step is only necessary if you do not plan to use the destination directory for anything else.
That's it! Following these steps will allow you to copy a folder from a specific commit in a Git repository to a local directory using the
git archive and