Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export all changed/added files from Git?

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!

like image 476
dr Hannibal Lecter Avatar asked Jun 08 '10 13:06

dr Hannibal Lecter


People also ask

How to add all modified files in Git add?

When you are dealing with Git add, you have multiple options to add all modified files. Let’s look at a few scenarios to understand the possibilities. Let’s initialize a new project. In this project, we have added a ReadMe.txt file. We used the “git add” command to add the ReadMe.txt. The add command is not only for adding files.

How do I add changes to a git repository?

Then, you have to use the commit command to make the changes official. When you are dealing with a lot of files and folders, it’s difficult to individually add each change. So you can use the following commands: $ git add .

How do I archive files between two commits in Git?

The archive function accepts a list of files to archive, which is what we want to do and is where our second command comes in. This will do the commit before the head, which is what I want most of the time but this could be changed to get files between two commits or anything you wanted, check out the help section in git for the diff command.

How to export diff between two versions of a Git file?

You can export diff using Tortoise Git to MS Windows: I right click and select TortoiseGit > Show Log and Log Messages will be open. Select two revisions and compare it. Difference between will be open. Select the files and Export selection to ... to a folder!


2 Answers

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 $(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).

like image 123
Cascabel Avatar answered Sep 20 '22 02:09

Cascabel


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]

like image 25
Altair7852 Avatar answered Sep 23 '22 02:09

Altair7852