1

rsync --delete does not work if the input for files is given by git ls-files

This is for syncing the two git repositories, wherein one is original and other is rsync backed up version.

I want files from some sub-directories of orig_repo to be synced in sync_repo, including the files that are deleted in orig_repo to be deleted in sync_repo.

The below code syncs both directories, the only problem is it does not delete files at destination end which are no longer present in the source directory.

git ls-files -z sub_dir1/ sub_dir2/ | rsync --omit-dir-times --chmod=u+w --files-from=- -av0 source_repo/ destination_repo/

I tried to add --delete flag like below:

git ls-files -z sub_dir1/ sub_dir2/ | rsync --omit-dir-times --chmod=u+w --files-from=- -av0 --delete source_repo/ destination_repo/

It did not work. Reason being, when we delete the file as: git rm file1

The git ls-files outputs individual file name and not the directory, so the deleted files are not known to destination end. Hence, I tried

find sub_dir1/ -type d -print | rsync --omit-dir-times --chmod=u+w --files-from=- -av0 --delete source_repo/ destination_repo/

It syncs all files into destination_repo but not specific subdirectories (sub_dir1, sub_dir2) so it does not work as intended.

I need both the repositories should be synced properly.

kajalp
  • 51
  • 5

0 Answers0