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

前端 未结 5 665
情歌与酒
情歌与酒 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:36

    Here's a solution using 7zip with a Custom Action (Tools > Options > Custom Actions > Add):

    Menu caption: > dist.zip
    
    [ ] Open in a separate window
    [ ] Show Full Output
    [X] Run command silently
    
    Script to run: X:\Your\path\to\7-Zip\7z.exe
    
    Parameters: a $REPO\dist.zip $FILE
    
    (Restart SourceTree after creation for the changes to take effect!)
    

    This action works from the context menu for Unstaged Files and changed files in commits from the Log / History (even with multiple files / multiple commits selected) and will add those files to a "dist.zip" in the repo root. Just note that the file will not be deleted before adding files, so if you want to start from scratch, remember to delete the zip file first.

    This has made it so much easier to update live systems with just the files that have changed, in projects where there's no build system involved. I wonder how I was able to live and work for so long without it. :-)

    0 讨论(0)
  • 2021-02-02 00:43

    I did this code for custom action on windwos .bat

    single commit (Search on google) [question]:Create archive of modified files in GIT via batch file

    setlocal enabledelayedexpansion
    set output=
    for /f %%G in ('git diff-tree --no-commit-id --name-only -r %1^^') do ( set output=!output! "%%G" )
    git archive -o update.zip %1 %output%
    endlocal
    

    Between to commits (Variation of the top one)

    setlocal enabledelayedexpansion
    set output=
    for /f %%G in ('git diff-tree --no-commit-id --name-only -r %2^^ %1') do ( set output=!output! "%%G" )
    git archive -o update.zip %1 %output%
    endlocal
    

    You have to set by parameter the $SHA

    0 讨论(0)
  • 2021-02-02 00:46

    From within sourcetree:

    • Choose the first commit to start from
    • Hold the shift key
    • Click on the last commit you want to export
    • Right click with the mouse: and choose create patch
    • Set the name of the file to save and you patch is ready

    enter image description here


    Using CLI:

    Open terminal (Icon on the sourcetree icon bar)

    Then type:

    git diff <sha-1>..HEAD > my_all_commits.diff
    

    It will generate a diff file with all the changes in the given range.


    How to generate single patch per commit

    git format-patch SHA-1..SHA-1.
    This commit will create set of patches per commit with all the changes in the commit. You can then choose to use them all or only to pick those you want to apply tot he second repo.

    Good Luck.

    0 讨论(0)
  • 2021-02-02 00:52

    Try this:

    git archive --output=test_zip.zip HEAD $(git diff --diff-filter=ACMRTUXB --name-only hash1 hash2)
    

    Just replace the hash 1 and hash 2 in the example with the desired commits hash and name the zip file where you want your change to be zipped.

    It works for me

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题