Lấy code từ repository về máy với đường dẫn đã sao chép từ repository
$ git checkout -b example
Tạo 1 nhánh example mới từ nhánh master
$ git branch
Hiển thị nhánh đang làm việc
$ git checkout master
Di chuyển về nhánh master
$ git branch -D example2
Xóa nhánh example2
$ git log
Xem lịch sử commit
$ git log --oneline
Xem lịch sử commit được rút gọn với mã SHA
$ 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
$ git diff
Hiển thị từng dòng code đã được chỉnh sửa trong file
$ 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
$ git pull
Lấy code mới nhất trên repository về
$ git revert (commit_hash)
Trở về commit bất kỳ trước đó
Create conflict and resovle conflict
Ở folder test file example1.txt tại nhánh master có nội dung như sau :
Commit và push file này lên nhánh master
Ở folder test2/test file example1.txt tại nhánh master có nội dung như sau:
Pull code lúc nãy push lên sẽ có thông báo conflict với file example1.txt
Mở file example1.txt và nội dung của nó như sau:
Đ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:
=> 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
Bài tập GIT buổi 1
Tạo repository mới
$ git init
Khởi tạo git
$ git add example1.txt
Khởi tạo và thêm file example1.txt
$ git commit -m "add example1 file"
Tạo commit cho file
$ git remote add origin git@github.com:at-hienpham/test.git
Thêm một kho chứa git để lấy dữ liệu
$ git push -u origin master
Push code lên repository vừa tạo
$ 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
$ git checkout -b example
Tạo 1 nhánh example mới từ nhánh master
$ git branch
Hiển thị nhánh đang làm việc
$ git checkout master
Di chuyển về nhánh master
$ git branch -D example2
Xóa nhánh example2
$ git log
Xem lịch sử commit
$ git log --oneline
Xem lịch sử commit được rút gọn với mã SHA
$ 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
$ git diff
Hiển thị từng dòng code đã được chỉnh sửa trong file
$ 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
$ git pull
Lấy code mới nhất trên repository về
$ git revert (commit_hash)
Trở về commit bất kỳ trước đó
Create conflict and resovle conflict
Ở
folder test
fileexample1.txt
tại nhánh master có nội dung như sau :Commit và push file này lên nhánh master
Ở
folder test2/test
fileexample1.txt
tại nhánh master có nội dung như sau:Pull code lúc nãy push lên sẽ có thông báo
conflict
với fileexample1.txt
Mở file example1.txt và nội dung của nó như sau:
Đ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:=> 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