mvn-quangtran-dn / GIT-PHP

0 stars 0 forks source link

G1_PHAM_THI_MINH_HIEN #9

Open ghost opened 6 years ago

ghost commented 6 years ago

Bài tập GIT buổi 1

Tạo repository mới

screenshot from 2018-06-20 08-35-33

$ git init

Khởi tạo git

screenshot from 2018-06-20 08-38-00

$ git add example1.txt

Khởi tạo và thêm file example1.txt

screenshot from 2018-06-20 09-02-31

$ git commit -m "add example1 file"

Tạo commit cho file

screenshot from 2018-06-20 09-03-13

$ git remote add origin git@github.com:at-hienpham/test.git

Thêm một kho chứa git để lấy dữ liệu

screenshot from 2018-06-20 08-53-34

$ git push -u origin master

Push code lên repository vừa tạo

screenshot from 2018-06-20 08-40-54

$ git clone git@github.com:at-hienpham/test.git

Lấy code từ repository về máy với đường dẫn đã sao chép từ repository

screenshot from 2018-06-20 08-45-45

$ git checkout -b example

Tạo 1 nhánh example mới từ nhánh master

screenshot from 2018-06-20 08-55-34

$ git branch

Hiển thị nhánh đang làm việc

screenshot from 2018-06-20 08-57-34

$ git checkout master

Di chuyển về nhánh master

screenshot from 2018-06-20 09-07-39

$ git branch -D example2

Xóa nhánh example2

screenshot from 2018-06-20 09-06-09

$ git log

Xem lịch sử commit

screenshot from 2018-06-20 09-09-33

$ git log --oneline

Xem lịch sử commit được rút gọn với mã SHA

screenshot from 2018-06-20 09-12-15

$ git commit --amend

Thay đổi commit đằng trước. Lệnh này được dùng để chỉnh sửa commit vừa tạo khi commit thiếu hoặc sai nội dung

screenshot from 2018-06-20 09-19-11 screenshot from 2018-06-20 09-18-24

$ git diff

Hiển thị từng dòng code đã được chỉnh sửa trong file

screenshot from 2018-06-20 09-26-31

$ git reset HEAD (file name)

Lệnh này để loại bỏ file example2.txt khỏi stage sau khi dùng git add . để add tất cả các file

screenshot from 2018-06-20 09-48-28 screenshot from 2018-06-20 09-48-51

$ git pull

Lấy code mới nhất trên repository về

screenshot from 2018-06-20 14-22-18

$ git revert (commit_hash)

Trở về commit bất kỳ trước đó

screenshot from 2018-06-23 14-08-25 screenshot from 2018-06-23 14-07-55

Create conflict and resovle conflict

folder test file example1.txt tại nhánh master có nội dung như sau :

screenshot from 2018-06-20 14-53-47

Commit và push file này lên nhánh master

screenshot from 2018-06-20 14-55-05

folder test2/test file example1.txt tại nhánh master có nội dung như sau:

screenshot from 2018-06-20 14-57-12

Pull code lúc nãy push lên sẽ có thông báo conflict với file example1.txt

screenshot from 2018-06-20 15-00-16

Mở file example1.txt và nội dung của nó như sau:

screenshot from 2018-06-20 15-01-35 screenshot from 2018-06-20 15-02-06

Đoạn bị xung đột được bắt đầu bằng<<<<<<< HEAD và kết thúc tại >>>>>>> 83c6e..... Xóa đi những ký hiệu trên và giữ lại nội dung cần chỉnh, nội dung của file sau khi lưu như sau:

screenshot from 2018-06-20 15-05-35

=> Confict đã được giải quyết Dùng lệnh git add, git commit và git push để đẩy file vừa mới chỉnh sửa conflict lên git

screenshot from 2018-06-23 13-03-00

mvn-quangtran-dn commented 6 years ago
ghost commented 6 years ago

Cảm ơn anh đã review. Em sẽ chỉnh sửa ạ.