简体   繁体   中英

Extract all files changed in repo since a certain date

I need to pull out all files changed since a certain date from my git repo to copy them into a separate repo.

Running the following grabs the list of file paths that I need:

git log --since="2021-10-21" --name-only --pretty=format: | sort > changed-files.txt

Manually copying this large list would be time-consuming and very error-prone.

Is there any way to extract or bundle this list of files to more easily move them?

Something like this may be just what you want

git log --since="2021-10-21" --name-only --pretty=format: | \
sort -u | \
grep -ve '^$' | \
xargs -I{} cp -v -u {} /destination/path

features

  • sort -u eliminates duplicates
  • grep -ve '^$' eliminates any empty lines (there was one in my output)
  • xargs replace from cp after xargs not working

If you wish to preserve directory structure, you can do it like this:

git log --since="2021-10-1" --name-only --pretty=format:  \
  | sort -u                                               \
  | xargs -I{} bash -c                                    \
    '[ -x {} ] && mkdir -p $(dirname tmp/{}) && cp -v {} tmp/{}'

This will:

  • Get a list of all changed or modified files since a certain date
  • Remove duplicates

Then, for each file:

  • Check if it still exists (removed files will show up as modified)
  • If so, create a directory for the file
  • And finally, copy the file into the given directory

All your files will then be in the tmp directory, with the same directory structure as in the original git repository.

(You shouldn't need to filter out empty lines because xargs takes care of that automatically)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM