generate file list modified since last commit and export to tar file

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMID_HASH | xargs tar -rf mytarfile.tar
################################################################################ # get all modified files since last commit and zip them to upload to live server ################################################################################ # delete previous tar output file rm mytarfile.tar -rf #rm c:/tarOutput/*.* -rf # get last commit id and store in variable declare RESULT=$(git log --format="%H" | head -n1) # generate file list and export to tar file git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $RESULT | xargs tar -rf mytarfile.tar # extract tar files to specified location tar -xf mytarfile.tar -C c:/tarOutput
Sample Output
tar file

1
2014-03-04 12:16:07

What Others Think

Nice. But, I'd make a small fix: Add "-z" to git and -0 (zero) to xargs to use a NUL character to delimit the filenames. That means your command will work even if the filenames contain whitespace. (Of course, as a Unix guy, none of my filenames ever contain whitespace :-) git diff-tree -z -r --no-commit-id --name-only --diff-filter=ACMRT COMMID_HASH | xargs -0 tar -rf mytarfile.tar
flatcap · 311 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: