Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git archive of repository with uncommitted changes

Tags:

How can I create an archive of the current repository including local uncommitted changes using git archive?

like image 220
Ton van den Heuvel Avatar asked May 04 '10 15:05

Ton van den Heuvel


People also ask

Does git archive include history?

Use Git Archive for Files The available list of formats can be retrieved with the git archive --list command. But the Git archive command includes only the files, not the history of those files. You can also use git archive branch to see the history of your branch/tree.

How does git archive work?

Git archive is a helpful utility for creating distributable packages of git repositories. Git archive can target specific refs of a repository and only package the contents of that ref. Git archive has several output formats that can utilize added compression.


2 Answers

I know this is old, but I think I found a solution.

Run:

stashName=`git stash create`; git archive <options> $stashName 

Since git wants a solid commit to make an archive, we can make a 'one off' commit using git stash. The create command just creates the stash commit (doesn't reset your working directory or push it to the stash stack) and returns the hash for it.

If you are worried about the space from the dangling commit, you can clean it up with a git gc --prune=now. Otherwise, just wait 2 weeks and it'll disappear.

like image 183
nevsan Avatar answered Dec 06 '22 10:12

nevsan


Improving nevsan's answer for my purpose - to archive latest code in any case (committed or not):

uploadStash=`git stash create`; git archive -o code_outgoing.zip ${uploadStash:-HEAD} 
like image 29
lahjaton_j Avatar answered Dec 06 '22 10:12

lahjaton_j