tl;dr
-
use syntax below
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id | tar -czf file.tgz -T -
$commit_id = commit sha id you want to archieve
-
to know commit id
git log
To exit git log command press q key.
Git Archieve only Changed File and folder on current commit
To create an archive of only the changed files and directories in a specific commit, follow these steps:
-
Identify the commit you want to create an archive for. You can do this using the
git log
command to show a list of all the commits in your repository. Make a note of the commit's SHA-1 hash. -
Use the
git diff-tree
command to identify the files and directories that have changed between the specified commit and its parent. Here's an example command:git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commitsha
This will output a list of file and directory names that have been added, copied, modified, renamed, or changed in some way in the specified commit.
-
Pipe the output of the
git diff-tree
command to thetar
command to create a compressed tar archive containing only the changed files and directories. Here's an example command:git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commitsha | tar -czf file.tgz -T -
This will create a compressed tar archive called
file.tgz
that contains only the changed files and directories in the specified commit. -
Extract the archive using the tar command. Here's an example command:
tar -xzf file.tgz
This will extract the contents of the archive to the current directory.
That's it! You now have a compressed archive containing only the files and directories that have changed in the specified commit. This can be useful for backups, sharing code with others, or simply keeping track of changes over time.