Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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?

like image 486
Mr Question Avatar asked Nov 08 '10 17:11

Mr Question


People also ask

How do you see what files were changed in git?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command.

How do you git add all modified files?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.

Can git track ZIP files?

In an uncompressed ZIP file, the archived files appear as-is in its content (together with some binary meta information before each file). If those archived files are plain-text files, this method will play nicely with Git.

What is the git command to add all files?

To add and commit files to a Git repository Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository.


2 Answers

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 modified-files.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.)

like image 170
Cascabel Avatar answered Oct 06 '22 13:10

Cascabel


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` > a.zip 

If you have removed files in a commit, to prevent a pathspec error use --diff-filter=d:

git archive --format=zip HEAD `git diff --diff-filter=d HEAD^ HEAD --name-only` > a.zip 

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, applying a patch only works if your target directory already contains the old version of your repository.

like image 37
Sven Marnach Avatar answered Oct 06 '22 12:10

Sven Marnach