Categories We Write About

Archive code changes from multiple repos

Archiving code changes from multiple repositories can be streamlined with the right strategy and tooling. Here’s a detailed approach to help you systematically archive changes across multiple repositories:


1. Define Scope and Objectives

  • Repositories Involved: List all the repositories you want to track.

  • Change Type: Decide whether you want full commits, diffs, or summaries.

  • Archive Format: Choose output format—plain text, markdown, JSON, HTML, or PDF.

  • Frequency: Determine whether this is a one-time or recurring task.


2. Gather Required Tools

You’ll need:

  • Git CLI (git)

  • Scripting language (e.g., Bash, Python)

  • Optional: GitHub/GitLab API access if working with remote repos


3. Automated Script to Archive Changes

Option A: Bash Script

bash
#!/bin/bash # List your repositories REPOS=( "/path/to/repo1" "/path/to/repo2" "/path/to/repo3" ) # Output directory ARCHIVE_DIR="$HOME/code_changes_archive" mkdir -p "$ARCHIVE_DIR" # Date range SINCE="2 weeks ago" for REPO in "${REPOS[@]}"; do REPO_NAME=$(basename "$REPO") cd "$REPO" || continue echo "Archiving changes for $REPO_NAME..." git fetch git log --since="$SINCE" --pretty=format:"%h - %an, %ar : %s" > "$ARCHIVE_DIR/${REPO_NAME}_changes.txt" done

Option B: Python Script

python
import os import subprocess from datetime import datetime repos = [ "/path/to/repo1", "/path/to/repo2", "/path/to/repo3" ] archive_dir = os.path.expanduser("~/code_changes_archive") os.makedirs(archive_dir, exist_ok=True) since = "2 weeks ago" for repo in repos: repo_name = os.path.basename(repo) output_file = os.path.join(archive_dir, f"{repo_name}_changes.txt") try: os.chdir(repo) subprocess.run(["git", "fetch"], check=True) log = subprocess.check_output([ "git", "log", f"--since={since}", "--pretty=format:%h - %an, %ar : %s" ]).decode("utf-8") with open(output_file, "w") as f: f.write(log) print(f"Archived changes for {repo_name}") except Exception as e: print(f"Error processing {repo_name}: {e}")

4. Optional Enhancements

  • Use GitHub API: To pull PR details, reviewers, labels.

  • Export to Markdown or PDF using pandoc.

  • Email Notifications using sendmail or third-party services.

  • Scheduled Task: Use cron (Linux/macOS) or Task Scheduler (Windows).


5. Version Control Your Archives

To keep track of archived logs:

bash
cd ~/code_changes_archive git init git add . git commit -m "Initial archive snapshot"

Automate weekly commits to log changes over time.


6. Cloud Storage (Optional)

Push archives to a remote Git repo, cloud storage (Google Drive, Dropbox via CLI), or AWS S3 for backup.


7. Naming Convention and Organization

Use consistent file naming:

repo-name_YYYY-MM-DD_changes.txt

Organize folders by:

  • Date: /2025-05/

  • Project: /project-name/


This process ensures all code changes from multiple repositories are consistently archived for audits, reporting, or backups.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About