</>
⌕
Senior #amend#force-push#force-with-lease#history

git commit --amend và vì sao nên dùng --force-with-lease

⚡ Trả lời nhanh

commit --amend thay commit cuối bằng commit mới (đổi message hoặc thêm file) nên hash đổi. Nếu đã push, phải force push. --force-with-lease chỉ ghi đè khi remote vẫn đúng như bạn lần cuối thấy, tránh vô tình xoá commit của đồng nghiệp như --force.

git add forgotten.js
git commit --amend --no-edit        # thêm file vào commit cuối
git commit --amend -m "fix: correct typo"

git push --force-with-lease                                  # an toàn hơn --force
git push --force-with-lease=feature:abc123 origin feature    # ghim hash kỳ vọng
--force--force-with-lease
Ghi đè vô điều kiệnCóKhông
Từ chối nếu remote có commit mới bạn chưa fetchKhôngCó
🃏 Ôn bằng flashcard