
유사한 파일을 포함하는 두 개의 디렉터리 트리(실제로는 macOS 볼륨)가 있고 두 소스 트리 사이에서 변경된 파일만 포함하는 세 번째 디렉터리 트리를 생성하려고 합니다.
어떻게 해야 합니까 rsync
? 아니면 이를 달성하기 위해 다른 도구를 사용해야 합니까?
답변1
- 사용동기화(기준으로이 답변):
SOURCE_TREE_1="/some/where/tree_1" SOURCE_TREE_2="/some/where/tree_2" DIFF_DIR="/some/where/diff" rsync --dry-run \ --recursive \ --checksum \ --itemize-changes \ "$SOURCE_TREE_1/" "$SOURCE_TREE_2" | # trailing '/' in source directory is necessary! grep -E '^>fc' | # grep files with different checksums cut -d ' ' -f 2- | while read file; do subdir="${file%/*}"; [ "$file" != "$subdir" ] && mkdir -p "$DIFF_DIR/$subdir"; # Change `"$SOURCE_TREE_1/$file"` to `"$SOURCE_TREE_1/$file"` in the next # line if you want copy from source tree #2. cp -a "$SOURCE_TREE_1/$file" "$DIFF_DIR/$file"; done
- 사용자식:
cd "$SOURCE_TREE_1" git init . git add . git commit -m 'Init' # Note: Here git may ask you to set name and email # replace all files with files from source tree #2 rm -rf $(git ls-tree --name-only HEAD) rsync --archive "$SOURCE_TREE_2/" . # show changes briefly: git status -uno # show changes for some file: git diff "path/to/file" # restore source tree #1 state git restore .