How to export all changed/added files from Git?
Asked Answered
O

2

11

I am very new to Git and I have a slight problem.

In SVN [this feels like an Only Fools and Horses story by uncle Albert.."during the war..."] when I wanted to update a production site with my latest changes, I'd do a diff in TSVN and export all the changed/added files between two revisions. As you can imagine, it was easy to get those files to a production site afterwards.

However, it seems like I'm unable to find an "export changed files" option in Git. I can do a diff and see the changes, I can get a list of files, but I can't actually export them. Is there a reasonable way to do this? Am I missing something simple?

Just to clarify once again, I need to export all the changes between two specific commits.

Thanks in advance!

Ouster answered 8/6, 2010 at 13:18 Comment(0)
H
17

How do you want to export them? You say you already have a list; what more do you want? Supposing you're getting your list with git diff --name-only ...

git archive --output=<file> HEAD $(git diff --name-only ...)

tar -czf <file> $(git diff --name-only ...)

cp --parents $(git diff --name-only ...) <export-directory>

Something like that?

Or you could even use the diff itself - it can be applied with git apply (or even patch, I believe).

Hinch answered 8/6, 2010 at 13:28 Comment(9)
The first option is working for me! Ideally, I would use the cp variant but keep the folder structure (I'm guessing it's a matter of parameters for git diff?) I can't believe it's that simple..thanks!Ouster
Just saw your edit.. Unfortunately, I can't use git apply or patch, I only have FTP access to the site :-/Ouster
@dr Hannibal Lecter: Yeah, I figured you needed to pass around actual files. And yeah, command substitution (the $(...)) is one of those key things that makes everything possible (and simple) in Linux shells.Hinch
Sadly, I'm currently 50% stuck on Windows, but git bash and cygwin tend to make my life easier.. even though I often have no idea what I'm doing :) Thanks again for the useful info!Ouster
How would you make a diff ignoring files with only modified permissions and not modified contents?Malevolent
with every day, I love git more! THIS IS AWESOME!Norseman
to use the third option here, you would probably want to add the --parents parameter to CP, so that it preserves file paths in the destinationCarboxylate
how do you perform this in TortoiseGit?Mccollum
Adding --diff-filter=AM to git diff to filter out deleted files and such may be usefulRanitta
C
3

Borrowing from few of the answers in here, here is another way to export files that are modified in the workspace:

git diff --diff-filter=ACMRT --name-only HEAD | xargs tar -rf export.tar

You might need to execute the following beforehand to add untracked files, if you need to include them in the diff:

git add *

[This works in git-bash in Windows]

Carmacarmack answered 23/4, 2017 at 18:49 Comment(2)
While executing this command in the windows slave machine, I'm getting the following error "'xargs' is not recognized as an internal or external command, operable program or batch file."Flatting
This assumes you run it in git-bash environment (different from regular command line), which has access to the additional unix toolsCarmacarmack

© 2022 - 2024 — McMap. All rights reserved.