Original link: https://blog.kelu.org/tech/2023/05/27/how-to-export-gits-changed-files.html
git archive -o "$(basename "$(pwd)").zip" HEAD $(git diff --name-only HEAD^ HEAD)
The meaning is as follows:
-
git archive
: used to create a Git archive file. -
-o "$(basename "$(pwd)").zip"
: Specifies the name of the output file. Here, we usebasename "$(pwd)"
to get the directory name of the current directory. -
HEAD
: A reference representing the commit we want to exportHEAD
is a pointer to the branch you are currently on, and it points to the latest commit.And
HEAD^
indicates the parent submission of the current submission, which is the penultimate submission. -
$(git diff --name-only HEAD^ HEAD)
: Used to get the list of changed files between the latest commit and the last commit.git diff --name-only HEAD^ HEAD
command returns relative paths to these files.
This article is transferred from: https://blog.kelu.org/tech/2023/05/27/how-to-export-gits-changed-files.html
This site is only for collection, and the copyright belongs to the original author.