How can I create an archive of the current repository including local uncommitted changes using git archive
?
git ls-files
is preferred cause it doesn't need to create any commit object.
git ls-files --recurse-submodules -z | tar --null -T - -czvf output.tar.gz
# git ls-files
# --recurse-submocules
# -z, split output lines with null
# tar
# -T -, read files from stdin
I'm using this command to export specify version to now (including uncommit changes file) changes by one line
git archive -o /path/to/save/temp.zip $(git stash create) $(git diff --name-only xxx_version_to_start)
You don't have to use git stash
anymore to create one artificial commit which would include your tracked change, for git archive
to operate on.
With Git 2.29 (Q4 2020), "git archive"(man) learns the "--add-file
" option to include untracked files into a snapshot from a tree-ish.
See commit df368fa, commit 2947a79, commit 200589a (19 Sep 2020) by René Scharfe (rscharfe).
(Merged by Junio C Hamano -- gitster -- in commit f6b06b4, 05 Oct 2020)
archive: add
--add-file
Signed-off-by: René Scharfe
Allow users to append non-tracked files.
This simplifies the generation of source packages with a few extra files, e.g. containing version information.
They get the same access times and user information as tracked files.
git archive
now includes in its man page:
--add-file=<file>
Add a non-tracked file to the archive.
Can be repeated to add multiple files.
The path of the file in the archive is built by concatenating the value for--prefix
(if any) and the basename of<file>
.
I also like the Git 2.30 alternative to tar.