Export All Modified and New Added Files in Git on Windows OS

Published on Friday, May 10, 2019

If we use Git to control our source version, we might have some chances to export all modified files and new added files to a specific directory.

There are many answers on the internet to resolve our requirement, most of them work well. However, seems only a feware for Windows OS.

How to Export All Modified and New Added Files in Git to Another Directory on Windows?

By now, we have only found out 1 answer that is for Windows OS, and it works perfect on Windows 7/8/10. Please check here - stackoverflow website.

Let's copy the command and explanation here:

for /f "usebackq tokens=*" %A in (`git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD~1 HEAD`) do echo FA|xcopy "%~fA" "C:\git_changed_files\%A"
  • echo FA answers the inevitable xcopy question about whether you're copying a file or a directory (file), and the possible question about overwriting a file (overwrite All)

  • usebackq allows us to use the output from our git command as the input to our do clause

  • HEAD~1 HEAD gets all differences between the previous commit and the current HEAD

  • %~fA transforms the git output into fully qualified paths (needed to change forward slashes to backslashes)

  • C:\git_changed_files\ is where you will find all the files that are different