Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Custom Action to create archive of modified files

Gabe Shackle February 8, 2014

I'm looking to create a custom action that will generate an archive file containing only the modified files within a specific commit. Here is the working git call:

git archive -o update.zip HEAD $(git diff-tree --no-commit-id --name-only -r COMMITID)

This works fine on the mac side and also when called directly from the command line but fails when called via a batch file. I suspect there is some kind of syntax issue specifically related to writing this call within a batch file but I'm unable to figure it out. The error generated is:

unknown option `no-commit-id`

I noticed that if I remove the no-commit-id and name-only options the error becomes:

fatal: path not found: $(git

Any help would be greatly appreciated!

8 answers

1 accepted

2 votes
Answer accepted
Gabe Shackle February 9, 2014

That's right. I was able to get an answer from StackOverflow:

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

http://stackoverflow.com/questions/21639415/create-archive-of-modified-files-in-git-via-batch-file

Karmalakas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 4, 2015

This doesn't work for the last commit. Let's say I merge some Release branch to Master and then I want to export all files that were merged. In a zip file I get full repository :/ But if I try to export some earlier commit, then I get just the files I need.

0 votes
Edu Wass
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 8, 2020

Feel free to check my Unix solution. Also lets you do it with multiple commits at once :)

https://stackoverflow.com/a/59650321/3480821

 

Screen-Shot-2020-01-08-17-36-19.75.png

0 votes
Connum
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 25, 2018

Here's a solution using 7zip with a Custom Action (Settings > 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 so long without it. :-)

necross220
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 19, 2019

This is the best working solution actuallyST.png

Pasquale Tedesco December 1, 2020

Thankyou.gif

0 votes
Baptiste Menadier June 23, 2014

Git native command do generate archive from one old commit to last commit:

git archive -o c:/maj.zip HEAD $(git diff --name-only HASHONLINE HEAD)

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2014

That is not a git command, it is a bash script using two separate native commands.

0 votes
Baptiste Menadier June 23, 2014

I may misunderstand something, but i don't understand how people update their project in production when using git as versioning tool without this command.

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2014

Two options:

1) Deploy the entire project, not just differences

2) Use that command (or something similar) without SourceTree.

0 votes
Gabe Shackle June 23, 2014

I've created a Gist that has the Mac and PC versions of the export script: https://gist.github.com/hereswhatidid/8876881

0 votes
Baptiste Menadier June 23, 2014

Why is there no option to do it from sourcetree native commands ? We need it when pushing on production... What are the files modified since last release ?

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2014

There is no way to do it from SourceTree native commands because there is no way to do it with git native commands.

You should be able to put the script in Gabe's answer in a script file, and run that script from a SourceTree custom action.

0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2014

So to be clear, you are putting the command in a batch file, and you are going to run the batch file from SourceTree's custom action?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events