Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git export files as zip/tar since specified commit till today

Tags:

git

bash

So I want to export all files starting from specific commit id till today (which may include subsequent commits), so I am doing this:

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commitId | xargs tar -rf output.tar

However, it seems this outputs file only that were modified in specified commit id ($commitId).

What I am looking for though is that it should export all files starting from specified commit id till today (including any further commits that might have happened during the course of the time).

like image 884
dev02 Avatar asked Jan 05 '17 10:01

dev02


1 Answers

git diff -z --name-only --diff-filter ACMRT ${commitId}~ HEAD | xargs -0 tar -rf output.tar
  1. git diff is sufficient; you don't need to use git diff-tree to find the list of changed filenames in a commit range.
  2. the -z option in git diff and -0 in xargs makes sure to use NUL output field terminators, otherwise any paths/filenames with spaces will cause your command to break.
  3. ${commitId}~ HEAD lists changes between the parent commit of ${commitId} (so the changes in that commit are included), and the most recent commit (HEAD).
like image 53
wjordan Avatar answered Oct 21 '22 06:10

wjordan