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) 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:
Then, for each file:
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.