【问题标题】:How to download the diffs present in the staging area in git如何下载 git 暂存区中存在的差异
【发布时间】:2016-08-07 16:53:42
【问题描述】:

除了 git stash 之外,有没有办法下载 git 暂存区中存在的文件的差异。我可能想要一种将差异下载为 tar 球的方法?

【问题讨论】:

    标签: git


    【解决方案1】:

    由于git archive 仅适用于树状结构,因此您需要:

    即:

    git add .
    git commit -m "tmp commit for export"
    git archive -o patch.zip @ $(git diff --name-only @~..@)
    git reset @~
    

    注意:如果这些文件的路径名中有空格,则可能需要:

    git diff -z --name-only @~ @ | xargs -0 git archive -o patch.zip @
    

    【讨论】:

      【解决方案2】:

      假设:

      • 您的作品已经与git add <filename> 放置在暂存区中
      • 您不想为了保存工作而创建临时提交
      • 您希望每个版本文件有一个差异/补丁

      for f in $(git diff --cached --name-only); do \
         p="$f.patch"; git diff --cached -- "$f" > "$p" && zip p.zip "$p" && rm "$p"; \
      done
        adding: file-1.c.patch (deflated 36%)
        adding: file-2.c.patch (deflated 44%)
      

      查看存档内容:

      unzip -l p.zip 
      Archive:  p.zip
        Length      Date    Time    Name
      ---------  ---------- -----   ----
            259  2016-08-07 19:24   file-1.c.patch
            347  2016-08-07 19:24   file-2.c.patch
      ---------                     -------
            606                     2 files
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-12
        • 2020-03-29
        • 2018-08-20
        • 1970-01-01
        • 2011-11-05
        • 1970-01-01
        • 2015-01-09
        • 2017-09-23
        相关资源
        最近更新 更多