Tình huống: bạn có commits ABC trên branch, teammate force push → remote history khác, commits của bạn "mất" trên remote.
Recovery (nếu bạn chưa pull): commits của bạn vẫn còn nguyên trong local repo — chỉ cần replay chúng lên history mới của remote:
bash
git fetch origin
git rebase origin/feature/shared # replay commits của bạn lên history mới
# Resolve conflicts nếu có
git push origin feature/sharedĐừng force push ngược lại để "đòi" history cũ — sẽ mất luôn work teammate vừa push.
Nếu bạn đã pull (local bị overwrite):
bash
git reflog # tìm commit trước khi pull
# Ví dụ: abc123 HEAD@{3}: commit: feat: my work
git cherry-pick abc123 # recover commitNếu teammate force push tới main: không recover bằng force push ngược lại (sẽ mất work của teammate). Coordinate với team, dùng git cherry-pick để apply lại commits bị mất lên main mới.
Phòng tránh: enable --force-with-lease và branch protection cho shared branches.