代码之家  ›  专栏  ›  技术社区  ›  Ton van den Heuvel

具有未提交更改的存储库的Git存档

git
  •  17
  • Ton van den Heuvel  · 技术社区  · 15 年前

    如何使用创建包含本地未提交更改的当前存储库的存档 git archive ?

    4 回复  |  直到 10 年前
        1
  •  2
  •   VonC    4 年前

    你不必使用 git stash 再创建一个包含跟踪更改的人工提交,例如 git archive 做手术。

    git archive " man ) 学习“知识” --add-file “将未跟踪的文件包含到树快照中的选项。”。

    看到了吗 commit df368fa , commit 2947a79 , commit 200589a (2020年9月19日) René Scharfe ( rscharfe ) .
    Junio C Hamano -- gitster -- 在里面 commit f6b06b4

    archive :添加 --添加文件

    签字人:Ren Scharfe

    允许用户附加非跟踪文件。
    这就简化了源程序包的生成,只需要几个额外的文件,例如包含版本信息的文件。

    现在包括在 man page

    --add-file=<file>

    将非跟踪文件添加到存档。

    归档文件中的文件路径是通过连接 --prefix (如有)以及 <file> .


    我也喜欢这个 Git 2.30 alternative to tar .

        2
  •  44
  •   nevsan    12 年前

    跑步:

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

    git stash . 这个 create 命令只是创建了stash commit(不重置工作目录或将其推送到stash堆栈)并返回其哈希值。

    如果您担心来自悬挂提交的空间,可以使用 git gc --prune=now . 否则,只要等两周,它就会消失。

        3
  •  15
  •   Edward Anderson    10 年前

    uploadStash=`git stash create`; git archive -o code_outgoing.zip ${uploadStash:-HEAD}
    
        4
  •  11
  •   Vianney Bajart    7 年前

    另一个解决方案 git ls-files :

    git ls-files -z | xargs -0 tar -czvf archive.tar.gz
    
        5
  •  2
  •   Mike Seplowitz    15 年前

    如果您还没有提交更改,那么 git archive 不会帮你的。如果你只是想要一张你工作区域的快照, tar 可能是你最好的选择。

        6
  •  1
  •   fhucho    4 年前

    这将创建一个包含所有工作树文件(git忽略的文件除外)的zip存档:

    git ls-files --others --exclude-standard --cached  | zip --names-stdin archive.zip
    
        7
  •  0
  •   Frank He    5 年前

    我使用这个命令将指定版本的更改导出到现在(包括未提交的更改文件)的一行

    git archive -o /path/to/save/temp.zip $(git stash create) $(git diff --name-only xxx_version_to_start)
    
        8
  •  0
  •   Simba Thomas Chaton    5 年前

    git ls-files 是首选,因为它不需要创建任何提交对象。

    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
    
        9
  •  0
  •   Lucio M. Tato    4 年前

    @fhucho's answer

    #backup.sh
    #remove final "/"
    repo=${1%"/"} 
    #create $repo-backup.zip
    cd $repo
    git ls-files --others --exclude-standard --cached  | zip --names-stdin ../$repo-backup.zip
    cd ..
    ls -l $repo-backup.zip
    

    用法:

    . backup.sh myrepo