1. Cài đặt Git
* Download và cài đặt Git-scm
https://git-scm.com/
2. Git status Lifecycle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
(1) (3) Untracked --------------► Staged --------------► first Commit (41ab78e) ====== Unmodified ---►┐ │ │ (4) │ Modified ◄-----------------------------------------------------------│ │ │ (2)│ │ │ │ (1) ▼ (3) │ Untracked --------------► Staged --------------► new Commit (2a64238) ===== Unmodified ------►│ │ │ (4) │ Modified ◄-----------------------------------------------------------│ │ │ (2)│ │ │ │ (1) ▼ (3) │ Untracked --------------► Staged --------------► new Commit (2a64238) ===== Unmodified ------►│ │ // Có 4 trạng thái của File: Untracked, Modified và Staged, và Unmodified // Trạng thái Untracked, Modified và Staged: chỉ lưu 1 phiên bản của 1 file ==> Nếu cùng 1 file đi vào trạng thái đó thì sẽ bị ghi đè // Trạng thái Unmodified là trạng thái Commit --> có thể lưu nhiều phiên bản |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Kiểm tra trạng thái file git status git log --oneline --graph --all -10 git add src/index.js (1) (2) get commit -m "add function xyz" (3) git restore --stage src/index.js (-1) (-2) git restore src/index.js (-4) // Đưa về trạng thái commit "2a64238" trước đó // Xóa tất cả các file làm việc, đưa hoàn toàn project về trạng thái đó git reset --hard 2a64238 (5) // Đưa về trạng thái commit "2a64238" trước đó // Các file đang làm việc được giữ và đưa về trạng thái "Staging" sau commit 2a64238 git reset --soft 2a64238 // Đưa về trạng thái commit "2a64238" trước đó // Các file đang làm việc được giữ và đưa về trạng thái "Working" sau commit 2a64238 git reset --mixed 2a64238 |
3. Remote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//Xem các remote đang sử dụng git remote git remote -v //Tạo một remote mới với kèm theo tên. VD: github với tên origin git remote add <name> <url> git remote add origin https://github.com/duycode/myproject.git git remote add second https://github.com/paulboone/ticgit.git //Xóa một remote. VD: xóa remote origin git remote remove <name> git remote remove origin //Push code lên git (sau khi add và commit) git push <name> <branch> git push origin master |
. 4. Reflog
1 |
git reflog --format='%C(auto)%h %<|(10)%gd %C(blue)%cr%C(reset) %gs (%s)' |