Wednesday, October 4, 2017

Try git

https://try.github.io/levels/1/challenges/
  1. git init
  2. git status (để xem có file untracked nào không)
  3. git add octocat.txt (để add file vào một staging area mà được git gọi là index)
  4. git status
  5. git commit -m "add cute octocat story"
  6. git add "*.txt"
  7. git commit -m 'add all octocat files'
  8. git log (để xem lịch sử commit)
  9. git remote add origin https://github.com/try-git/try_git.git (để add một remote repo vào, và đặt trên remote repo đó là origin )
  10. git push -u origin master (để đẩy các file trong local repo lên remote repo)
    • origin: tên gọi của remote repo
    • master: là tên của 1 local branch (nằm trong local repo)
    • -u: để yêu cầu git nhơ các tham số (remote repo nào và local branch nào). lần sau chỉ cần gõ 'git push'
  11. git pull origin master (kéo từ remote repo có tên là origin => kéo về local branch có tên là master)
  12. git diff HEAD (để xem sự khác nhau của remote repo: từ lần mình commit cuối cùng => đến hiện tại)
  13. git add octofamily/octodog.txt
  14. git diff --staged (để xem những thay đổi khi mình add thêm file vào staging area)
  15. git reset octofamily/octodog.txt (để unstage file)
  16. git checkout -- octocat.txt (để đưa cả local branch về lần cuối cùng mà tôi commit file octocat.txt )
  17. git branch clean_up (tạo mới 1 local branch tên là clean_up, nó sẽ được khởi tạo ban đầu giống với branch hiện tại)
  18. git branch (để xem hiện tại có những branch nào, và chúng ta đang thao tác trên branch nào)
  19. git checkout clean_up (để chuyển branch hiện tại : master => clean_up)
  20. git rm '*.txt' (vừa xóa file khỏi ổ cứng, và cũng 'stage the removal of the files')
  21. git status (xem trạng thái của staging area)
  22. git commit -m 'remove all the cats'
  23. git checkout master (chuyển branch hiện tại sang master)
  24. git merge clean_up (merge branch clean_up với branch hiện tại)
  25. git branch -d clean_up (xóa branch clean_up)
  26. git push (đẩy từ master => remote repo, branch origin)

2 comments:

  1. git reset: ngược lại với git add
    git checkout --file (sd để xóa những thay đổi trên file ) (file đó phải chưa được add vào staged, tức là chưa dùng lệnh git add file)

    ReplyDelete
  2. git revert ngược lại với git commit

    ReplyDelete