2

I found a Git command but it only export file names between commit ids and save in a file

git diff --name-only commitid1 commitid2 > ../result.txt

An example for result.txt:

Web/A/Recoverpw.aspx
Web/B/Root.aspx

But I want to export them as files in a folder in structure. Example:

Web
|__A
   |__Recoverpw.aspx
|__B
   |__Root.aspx

Exported files must be lastest, got from local respository. Please help me. Thanks.

Leo Vo
  • 9,980
  • 9
  • 56
  • 78
  • "latest" right? But isn't that a vague requirement? assuming by latest you mean the tip of a branch(local) and there could exist multiple branches – Bleeding Fingers Jun 14 '13 at 07:15
  • I don't think Git will do this for you. You already have a list of files, look for a way to post-process that into the format you want. Perhaps use the -P option of [tree(1)](http://linux.die.net/man/1/tree). – Peter Lundgren Jun 14 '13 at 07:23
  • @hus787, lastest from my local repository, don't take care branches. – Leo Vo Jun 14 '13 at 07:32

1 Answers1

0

The only commands which comes close would be git archive, for which you can specify a list of path you want to export in a (zip or tar) archive, you could un-archive elsewhere.

But that isn't a convenient way to get only the files you need.

The other way would be to:

  • clone your local repo
  • delete all the files not listed your git diff output

Actually, an easier way would be to copy each file from the git diff with their path.
See "linux: copy and create destination dir if it does not exist"

cp --parents a/b/c existing_dir

copies the file 'a/b/c' to 'existing_dir/a/b/c', creating any missing intermediate directories.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note to self: other `cp` alternatives at http://stackoverflow.com/questions/947954/how-to-have-the-cp-command-create-any-necessary-folders-for-copying-a-file-to-a – VonC Jun 14 '13 at 07:22
  • Thanks, I wrote a VB Script on Windows myself and it runs well. – Leo Vo Jun 21 '13 at 03:00