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 logTo 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 logcommand 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-treecommand 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 $commitshaThis 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-treecommand to thetarcommand 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.tgzthat 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.tgzThis 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.