Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export only modified and added files with folder structure in Git

Tags:

git

git-diff

I would like to get a list of modified and added files in an specific commit so that I can export them and generate a package with the file structure.

The idea is to get the package and extract it on the server. For many reasons I can't create a hook to pull the repo automatically and the easiest way I have to keep the server updated is generating this package.

like image 774
Michael Kuhinica Avatar asked Dec 27 '10 19:12

Michael Kuhinica


People also ask

What is git diff tree?

By default, git diff-tree --stdin shows differences, either in machine-readable form (without -p ) or in patch form (with -p ). This output can be suppressed. It is only useful with -v flag. -v. This flag causes git diff-tree --stdin to also show the commit message before the differences.

What does git diff head do?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.

How do I export a file from git?

There is no "git export" command, so instead you use the "git archive" command. By default, "git archive" produces its output in a tar format, so all you have to do is pipe that output into gzip or bzip2 or other.


1 Answers

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id
  1. git diff-tree -r $commit_id:

    Take a diff of the given commit to its parent(s) (including all subdirectories, not just the top directory).

  2. --no-commit-id --name-only:

    Do not output the commit SHA1. Output only the names of the affected files instead of a full diff.

  3. --diff-filter=ACMRT:

    Only show files added, copied, modified, renamed or that had their type changed (eg. file → symlink) in this commit. This leaves out deleted files.


UPDATE FROM THE COMMENT:
Base on the question context and the comments below, with the following command, you can get the ACMRT files as a .tar file with their folder structure.

git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id | tar -czf file.tgz -T - 
like image 70
Aristotle Pagaltzis Avatar answered Sep 19 '22 09:09

Aristotle Pagaltzis