10 November 2017

GIT story

Tổng hợp lệnh cmd làm việc với GIT
GIT 
/*--[Clone code]--Checkout--*/
git clone https://server/namespace/project.git

/*--[0]--Init git flow--*/
--Khởi tạo và lấy branch master và develop
git flow init 
khi chạy lệnh này chúng ta chỉ việc nhất enter cho tới khi chạy hết thì dùng lệnh tiếp theo để xem có nhánh develop & master chưa
git branch 
Xem danh sách các nhánh

/*--[1]--Create feature branch--*/
--Tạo mới một branch có tên 'feature/ABC'
--lệnh flow start là tạo branch và bắt đầu tại điểm develop header
git flow feature start ABC
--lệnh checkout -b là tạo branch mới nhưng không nằm tại điểm develop header hạn chế dùng lệnh này
git checkout -b feature/ABC

/*--[2]--Push source to origin--*/
--Lựa chọn file đưa lên git
git add *
--Commit file đã chọn
git commit -am "message"
--Push đẩy source vào branch
git push origin feature/ABC

/*--[3]--Rebase Fix conflic--*/
--Kéo source mới từ remote develop về khi chạy xong tool code sẽ chỉ ra các phần bị conflic develop với nhánh 'feature/ABC'
git pull --rebase origin develop
--Sửa lại các file có conflic lựa chọn phần code phù hợp và save file xong
git add *

/*--[3.1]--VD: Thông báo conflic trên IDE VScode--*/
- Accep current change - lấy mới nhất từ develop
- Accep comming change - lấy code của tôi
- Accep aboth lấy cả hai
- Note: lưu ý nhớ save file sau khi chỉnh sửa file nào đó

/*--[4]--Fix conflic --continue--*/
--Sau khi add all các file bị conflic vừa sửa ngon thi tiếp câu lệnh
git rebase --continue
--Lại thấy hiển thị tiếp conflic thì lại chọn phần code phù hợp và save file xong
git add *
--Sau khi add lại tiếp câu lệnh
git rebase --continue

/*--[5]--Push source code--*/
--cứ lặp đi lặp lại khi nào hết conflic thì đầy source hợp nhất của develop + feature/ABC lên nhánh feature/ABC
git push -f origin feature/ABC
NOTE: only use -f after using rebase

/*--[5.1]--Nếu muốn hủy rebase--*/
git rebase --abort

/*--[6]--Request merge source to develop--*/
/*--Rebase lùi về 4 commit--*/
git rebase -i HEAD~4
git push origin <branch> -f
/*-- Squash commit --*/
git rebase -i <id> or HEAD~4

change pick => squash
(Không sửa pick đầu tiên chỉ sửa squanh cái thứ hai trở đi)

Note: vim
i insert
:wq save
Esc thoát

git push origin -f <branch_name>
/*--Edit message commit trên remote--*/
git commit --amend -m "New commit message"
git push <remote> <branch> --force or -f
/*--MỘT SỐ LỆNH CẦN DÙNG NHIỀU NHẤT BỔ SUNG--*/
--Đăng nhập Git
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

/*--Remote tới repository--*/
git remote add origin https://github.com/id1945/react-shopping-cart.git

/*--Thay đổi URL Remote--*/
git remote set-url origin https://github.com/id1945/reactjs-redux.git

/*--Remove github or gitlab--*/
git remote remove github
git remote remove gitlab

/*--Remote add  github or gitlab--*/
git remote add gitlab https://xxx/xxx.git

/*--Kiểm tra thông tin xác thực gitHub... mọi lúc!--*/
Mọi thứ diễn ra tuyệt vời cho đến khi tôi commit những thay đổi của mình. 
Mọi lần commit đều kiểm tra thông tin đăng nhập mới!
Tôi không muốn nhập username và password GitHub của mình mỗi lần tôi commit thứ gì đó.
Tôi đã dùng thử cách này và nó đã không thông báo nữa.
git config --global credential.helper wincred

--Kiểm tra file nào đã bị thay đổi
--Màu đỏ là bị thay đổi, sau khi dùng git add * thì sẽ màu xanh lá cây
git status

--Kiểm tra đang ở nhánh nào
git branch

--Lệnh Xóa branch trên local
git branch -D feature/ABC

--Lệnh xóa branch trên remote
git push origin --delete feature/ABC

--Chuyển sang nhánh khác
git checkout .
git checkout feature/DEF

--Undo code toàn bộ
git checkout -- .

--Undo một file
git checkout -- <file_name>

--Undo code có lựa chọn
git checkout -p

--Kéo source mới nhất từ develop về
git pull origin develop

-- Đưa về id, toàn bộ commit phía sau bị xoá khỏi graph
git reset --hard <id>
NOTE: Tuy nhiên bạn vẫn có thể quay lại commit id đó nếu bạn copy và lưu id đó.

-- Đưa về id, vẫn giữ code của commit phía sau ở trang thái đã được add
git reset --soft <id>

-- Đưa về id, vẫn giữ code của commit phía sau ở trạng thái chưa được add
git reset --mixed <id>

--Khi lệnh reset --hard vô tác dụng chúng ta cần dùng
git reset --all
git reset --hard origin/{branch_name}

--Xem đồ họa Log của các branch cái nhìn tổng thể dễ hiểu
git log --all --graph --decorate
NOTE: bấm phím Q để thoát
git log -3 chỉ lấy 3 bản ghi

--REVERT COMMIT
git reset --hard <id>
git push -f origin (ten nhanh)

--Xem lại toàn bộ lịch sử commit
git reflog

--Kiểm tra lại các file sẽ xoa cho chắc
git clean -n

--Tiến hanh xoa bỏ
git clean -f

-- cherry-pick dùng để lấy code của id commit đó từ remote về branch hiện tại
git cherry-pick <id>
note: git cherry-pick để xem thêm các options lệnh (Cần xử lý conflic như rebase)

/*--Ignoring--*/
Ngăn chặn commit file
vd: file có đuôi .gitignore_global
git config --global core.excludesfile ~/.gitignore_global
hoặc folder node_module
git config --global core.excludesfile ~/node_modules

/*-- SSH KEY --*/
1.Generate ssh key:
ssh-keygen -t rsa -C "git@github.com:id1945/demo.git"
2.Add ssh key to gitlab
Go to C:/users/yourname/.ssh/id_rsa.pub and
Copy the content of that file
Use this data to add “ssh key” on gitlab (ssh key on Gitlab Profile Setting)
--Lệnh build source code AOT Angular
yarn build
or
ng build --prod
or
ng build --prod --base-href "/<repository-name>/"

---Optimizer
ng build --prod --build-optimizer

--Build debug JIT
yarn build:opt 'Không có debug'
of yarn build 'Có debug

--Update angular version
ng update @angular/core @angular/cli
or
ng update @angular/core @angular/cli --next

-- Pull project github to Stackblitz
https://stackblitz.com/fork/github/GITHUB_USER/GITHUB_REPOSITORY
Giết port đang chạy
netstat -a -n -o
taskkill -f /pid 7900

// Count log git
git log --author='id1945' --since='1 week ago' --oneline --shortstat -C
// LOCALHOST PUBLIC INTERNET
--Sử dụng ngrok--
Download | Document
ngrok http 8080 -host-header="localhost:8080"
ngrok http --host-header=rewrite 8080

--Access to localhost from other machine--
Bước 1: Cài đặt Windows Firewall turn off 3 trạng thái firewall
Bước 2: ng serve --host 0.0.0.0
Bước 3: test thử http://192.168.x.x:4200

--Eg
ng serve --port 8080 --host 192.168.53.180 or 0.0.0.0
/*-- NPM ---*/
npm i -D là viết tắt của npm install --save-dev
npm i -S là viết tắt của npm install --save

// Add cli into scripts package.json
npm pkg set scripts.prepare="husky install"
// Cách gỡ lỗi node_module
1. npm cache verify
2. xoá package-lock.json
3. xoá node_modules
4. npm install -f
// Tạo file test trên win
fsutil file createnew DummyTextFile1.txt 104857600
Convert GB to B 

// Xóa node-module
rm -rf node_modules (gitbass)
Refer: 
https://www.cloudways.com/blog/manage-branches-and-resolve-conflicts-git/
https://alligator.io/angular/custom-form-control/
https://github.com/angular/angular-cli/wiki
https://leochh.github.io/Notes/Frontend/Angular.html
Download tool git
https://git-extensions-documentation.readthedocs.io/en/latest/
Linux
Truy cập server linux sftp://developer@192.168.0.203/
Tổng hợp các lệnh gen với Angular CLI
Thành phần Sử dụng
Create App ng new myProject
Component ng g component my-new-component
Directive ng g directive my-new-directive
Pipe ng g pipe my-new-pipe
Service ng g pipe my-new-pipe
Class ng g class my-new-class
Guard ng g guard my-new-guard
Interface ng g interface my-new-interface
Enum ng g enum my-new-enum
Module ng g module my-module
Module + Router ng g m my-new-name --routing
service not spec ng g s guards/roleGuard --spec false
Remove ng destroy component app-testing

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang