Git archive of repository with uncommitted changes

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

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

回答1:

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.



回答2:

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}


回答3:

Another solution with git ls-files :

git ls-files -z | xargs -0 tar -czvf archive.tar.gz


回答4:

If you haven't committed the changes, then git archive won't help you. If you just want a snapshot of your working area, tar is probably your best bet.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!