Git: how to get all the files changed and new files in a folder or zip?

0 votes
asked Nov 8, 2010 by mr-question

As my question says, after changing files and adding new files in my repository, I normally commit files with git, but sometimes I need all the modified / changed files copied to a folder for organizing-myself reasons.

Any option?

5 Answers

0 votes
answered Nov 8, 2010 by sven-marnach

To do exactly what you requested (assuming you already committed and want to create an archive of the files changed by the last commit), you could do

git archive --format=zip HEAD `git diff HEAD^ HEAD --name-only` >

But maybe you actually want to create a patch using

git diff HEAD^ HEAD > a.patch

and apply this patch where you need it using

patch -p1 < a.patch

Of course, this only works if your target directory already contains the old version of your repository.

0 votes
answered Nov 8, 2010 by jefromi

Assuming you mean you haven't yet committed, and want to package up all of the files that currently have local modifications, you can get the list of modified files with git ls-files --modified. If you want the files which were changed by the last commit, you could use git diff --name-only HEAD^. Where you go from there is up to you. Examples:

zip $(git ls-files --modified)
cp $(git ls-files --modified) ../modified-files

Note that this is using the versions of files in the working tree currently.

If you have spaces in filenames, you'll have to go to a little more trouble.

(Of course, depending on what you're really trying to do, you might be looking for git stash, which stashes away all modified files and leaves you with a clean working tree, or you could simply want to make a temporary branch to commit to.)

0 votes
answered Nov 14, 2012 by aftershock

If you use TortoiseGIt, it provides this too.
Choose the folder, in explorer
Right click,Choose menu, TortoiseGit-> Show Log.

Select working directory and the last commiitted version.
Right click. Compare revisions. Select files you want to save/export.
Right Click. Export to folder. Done.

0 votes
answered Nov 27, 2016 by user3448451
mkdir -p /c/temp/blah && cp $(git diff <your commit hash> --name-only) /c/temp/blah

I'm using Git Bash on windows.

0 votes
answered Sep 15, 2017 by chauhants

Here is a script which can make this process a lot easier, it will copy all changed file to used defined directory and also maintain the directory structure of code base.

run: sh


FILES=`git ls-files --modified`
for x in $FILES
        echo "MY Dir = $prev_dir"
        mkdir -p $1/$x
        cd $1/$x
        cd ../
        rm -r *
        cp $prev_dir/$x ./.
        cd $prev_dir


Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter