How to export all changed files between two Git commits in SourceTree?

前端 未结 5 745
情歌与酒
情歌与酒 2021-02-02 00:03

In TortoiseGit and TortoiseSVN it is possible to export all changed files between two revisions, including the directory structure, to an external folder.

Is there a way

5条回答
  •  没有蜡笔的小新
    2021-02-02 00:58

    Here's how I did it, using a custom action + a bash script. Please note this solution is for Unix, but you should be able to replicate this into a Windows .bat script.

    The script

    I'm going to save this as: archive-commit.sh

    #!/bin/sh
    HASH1=${1}
    HOWMANYCOMMITS=${2:-1}
    HASH2=$(git rev-parse $HASH1~$HOWMANYCOMMITS)
    DATE="$(date "+%m_%d_%Y_%H%M")"
    FILENAME="deploy-$DATE.zip" # Change this to wherever you want to save the file
    git archive -o $FILENAME $HASH2 $(git diff --diff-filter=ACMRTUXB --name-only $HASH1 $HASH2)
    

    When calling for example:

    ./archive-commit.sh 17f6ca1993018761f7b936d46d2d600d4ee5ef85

    It will create a zip of that commit compared to its precedent commit.

    The script will also take a last numeric argument, let's say:

    ./archive-commit.sh 17f6ca1993018761f7b936d46d2d600d4ee5ef85 3

    It will create a .zip of this commit + the 2 previous ones (so the total 3).

    The custom action in SourceTree

    Now to integrate this into SourceTree you can create your custom actions like this (change the script target to where you've saved the script):

    I have to create multiple actions, because right now SourceTree isn't able to get the two hashes if you select multiple commits AFAIK.

    The Result

    Now you'll have a convenient way to export zips when right-clicking over a commit directly in SourceTree.

提交回复
热议问题