Git doesn’t care. When you rebase, it will faithfully replay every commit, every diff — including the ones that accidentally dump PII into a file. If those logs land in production, you’ve created a liability that no hotfix can erase.
The fix starts before code ever ships. Masking PII in production logs isn’t a “nice-to-have.” It’s an operational guardrail. The best approach combines strict CI/CD pipeline rules with runtime log sanitization. You commit clean. You deploy clean. You never store raw personally identifiable information.
Start with a logging library that supports field-level redaction. Configure it to identify and mask emails, phone numbers, addresses, and any user IDs before the logs are written. Use regex patterns informed by actual production data formats. Keep the patterns in source control, versioned, and reviewed like code.
Next, audit your Git history. If you suspect PII landed in previous commits, rebase with precision. Rewrite history using tools like git filter-repo to strip sensitive data from all branches. Confirm by scanning the rewritten history with a PII detection tool. No shortcut here — it’s the only way to ensure nothing survives from older commits.