问题
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 to do so in Atlassian SourceTree (for Windows)?
回答1:
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
回答2:
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
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.
回答3:
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. :-)
回答4:
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
来源:https://stackoverflow.com/questions/30482130/how-to-export-all-changed-files-between-two-git-commits-in-sourcetree