Files
lcbp3/specs/05-Engineering-Guidelines/05-05-git-cheatsheet.md
admin 5eff8861e1
All checks were successful
Build and Deploy / deploy (push) Successful in 1m0s
refactor(specs): merge 08-infrastructure into canonical 04-06 dirs
- Append live QNAP configs to 04-01-docker-compose.md (Appendix A)
  - MariaDB+PMA, Redis+Elasticsearch, NPM, Gitea, n8n, App stack
- Append SSH setup + Secrets management to 04-06-security-operations.md
  - Appendix A: SSH key setup, config, hardening, port forwarding
  - Appendix B: .env structure, secret generation, rotation, GPG backup
- Append QNAP/Gitea CI/CD docs to 04-04-deployment-guide.md
  - Appendix A: Container Station deployment steps
  - Appendix B: Gitea Actions CI/CD pipeline setup
  - Appendix C: act_runner (ASUSTOR) installation
- Move Git_command.md -> 05-Engineering-Guidelines/05-05-git-cheatsheet.md
- Move docker-compose-app.yml, lcbp3-monitoring.yml, lcbp3-registry.yml,
  grafana/ -> 04-Infrastructure-OPS/
- Archive lcbp3-db.md -> 99-archives/
- Remove all legacy 08-infrastructure/* files from git
- Remove Google OAuth client_secret JSON from git index (security)
- Add .gitignore rules: *client_secret*.json, *service_account*.json,
  specs/08-infrastructure/
- Update 04-Infrastructure-OPS/README.md with new file index
2026-02-23 15:03:35 +07:00

4.2 KiB
Raw Blame History

คำสั่งตั้งค่า Gitea ใหม่ทั้งหมด + คำสั่งใช้งานประจำวัน / แก้ปัญหา / branch”


📘 Git + Gitea (QNAP / Container Station) Cheat Sheet คู่มือนี้รวบรวม:

  • คำสั่งตั้งค่า Gitea ใหม่ทั้งหมด
  • คำสั่งใช้งาน Git ประจำวัน
  • การแก้ไขปัญหา repository
  • การทำงานกับ branch
  • การ reset / clone / merge / rebase

🧩 SECTION 1 การตั้งค่า Gitea ใหม่ทั้งหมด

🔹 1) เคลียร์ host key เดิม ใช้เมื่อ Gitea ถูก reset ใหม่ หรือ IP / key เปลี่ยน

ssh-keygen -R "[git.np-dms.work]:2222"

🔹 2) เชื่อมต่อครั้งแรก (จะมีคำถาม fingerprint)

ssh -T git@git.np-dms.work -p 2222

🔹 3) แสดง SSH public key เพื่อเพิ่มใน Gitea

cat /root/.ssh/id_ed25519.pub
cat /root/.ssh/id_rsa.pub

🔹 4) เพิ่ม remote ใหม่ (หากยังไม่ได้เพิ่ม)

git remote add origin ssh://git@git.np-dms.work:2222/np-dms/lcbp3.git

🔹 5) ลบ remote เดิมหากผิด

git remote remove origin

🔹 6) Push ครั้งแรกหลังตั้งค่า

git push -u origin main

🔹 7) Clone repo ใหม่ทั้งหมด

git clone ssh://git@git.np-dms.work:2222/np-dms/lcbp3.git

🧩 SECTION 2 คำสั่ง Git ใช้งานประจำวัน

🟦 ตรวจสอบสถานะงาน

git status

🟦 ดูว่าแก้ไฟล์อะไรไป

git diff

🟦 เพิ่มไฟล์ทั้งหมด

git add .

🟦 Commit การแก้ไข

git commit -m "message"

🟦 Push

git push

🟦 Pull (ดึงงานล่าสุด)

git pull

🟦 Pull (ดึงงานล่าสุด) แบบ rebase

git pull --rebase

🟦 ดู log

git log

🧩 SECTION 3 ทำงานกับ Branch

ดู branch ทั้งหมด

git branch

สร้าง branch ใหม่

git checkout -b feature/login-page

สลับ branch

git checkout main

ส่ง branch ขึ้น Gitea

git push -u origin feature/login-page

ลบ branch ในเครื่อง

git branch -d feature/login-page

ลบ branch บน Gitea

git push origin --delete feature/login-page

Merge branch → main

git checkout main
git pull
git merge feature/login-page
git push

Rebase เพื่อให้ history สวย

git checkout feature/login-page
git rebase main
git checkout main
git merge feature/login-page
git push

🧩 SECTION 4 แก้ไขปัญหา Repo

🔴 (1) Reset repo ทั้งหมดให้เหมือน remote

⚠ ใช้เมื่อไฟล์ในเครื่องพัง หรือแก้จนเละ

git fetch --all
git reset --hard origin/main

🔴 (2) แก้ปัญหา conflict ตอน pull

git pull --rebase

🔴 (3) ดู remote ว่าชี้ไปทางไหน

git remote -v

🔴 (4) เปลี่ยน remote ใหม่

git remote remove origin
git remote add origin ssh://git@git.np-dms.work:2222/np-dms/lcbp3.git

🔴 (5) Commit message ผิด แก้ใหม่

git commit --amend

🔴 (6) ย้อน commit ล่าสุด (ไม่ลบไฟล์)

git reset --soft HEAD~1

🔴 (7) ดู log แบบสรุป

git log --oneline --graph

🔴 (8) Clone repo ใหม่ทั้งหมด (เมื่อพังหนัก)

rm -rf lcbp3
git clone ssh://git@git.np-dms.work:2222/np-dms/lcbp3.git

📌 END