The simple and easy and obviously correct way to do it is: just make a commit (as bk2204 suggests).
But, since git archive
takes a <tree-ish>
, you can do this without making a commit. Just make the tree part of a commit, which is half (or more) of an actual commit, and then use that:
git archive [additional options] $(git write-tree)
The issue here is that git write-tree
will write whatever is in the index right now. This means you need to add all updated files to the index, even if you're not going to make a commit. You could do that with a temporary index, if you want to get extra fancy, but it's easier to just add -u
first:
git add -u
git archive [additional options] $(git write-tree)
Another way to get the work-tree files into a commit, without making a commit yourself, is to use git stash
to do the job. This will write the current work-tree to a new commit. Hence:
git stash push
git archive [additional options] refs/stash
git stash pop --index
would do the job, more or less. The less occurs when there is nothing to stash, in which case git stash push
does nothing and you should not run git stash pop
. In this particular case, you can archive HEAD
—but it's annoying to detect whether git stash push
did anything. You can add more layers of scripting to deal with that, but really, what's wrong with just committing now?