Đây là tình huống nghiêm trọng. Hành động ngay:
Bước 1: Không làm gì thêm trên main, thông báo team stop pulling.
Bước 2: Tìm commit cuối cùng đúng trên GitHub:
- Vào GitHub → repo → Commits history → tìm commit trước force push
- Hoặc: GitHub lưu reflog nội bộ, Contact GitHub Support nếu critical
Bước 3: Tìm trên local của bất kỳ teammate nào chưa pull:
# Trên máy teammate chưa pull (họ vẫn có local history cũ):
git log --oneline # KHÔNG có origin/ — local log thấy history cũ
# git log --oneline origin/main sẽ thấy history MỚI (đã bị overwrite)
# Nhờ teammate dùng local commit hash của họ để restore:
git push --force-with-lease origin <good-hash>:main # dùng force-with-lease an toàn hơnBước 4: Nếu có backup tag:
git checkout v2.3.0 # tag trước force push
git checkout -b main-recovery
git push --force origin main-recovery
# Tạo PR vào mainBước 5: Nếu không ai có — reflog local:
git reflog # trên máy bạn
# Tìm hash trước khi force push
git push --force origin <old-hash>:mainPhòng tránh: branch protection với Include administrators, không bao giờ dùng --force trên main.
This is a critical situation. Act immediately:
Step 1: Do nothing else on main, notify the team to stop pulling.
Step 2: Find the last correct commit on GitHub:
- Go to GitHub → repo → Commits history → find the commit before the force push
- Or: GitHub stores internal reflogs — contact GitHub Support if critical
Step 3: Find it on any teammate's machine that has not pulled:
# On a teammate's machine that has NOT pulled yet (they still have old local history):
git log --oneline # NO origin/ prefix — local log shows the old history
# git log --oneline origin/main would show the NEW (overwritten) history
# Ask teammate to restore using their local commit hash:
git push --force-with-lease origin <good-hash>:main # use force-with-lease, safer than --forceStep 4: If a backup tag exists:
git checkout v2.3.0 # tag from before the force push
git checkout -b main-recovery
git push --force origin main-recovery
# Create PR into mainStep 5: If nobody has it — local reflog:
git reflog # on your own machine
# Find the hash from before the force push
git push --force origin <old-hash>:mainPrevention: branch protection with Include administrators enabled, never use bare --force on main.