Bỏ qua

Các lệnh Git thường dùng

GitHub - GitAlias/gitalias: Git alias commands for faster easier version control
GitHub - initialcommit-com/git-sim: Visually simulate Git operations in your own repos with a single terminal command.

Xem danh sách tất cả commit

git log --oneline
git log --oneline --graph
git log --pretty='%C(yellow)%h %C(cyan)%cd%C(auto)%d %Creset%s' --graph --date=relative --date-order

Xem những thay đổi của một commit

git show --stat <commit>
git diff <commit>^!

Xem danh sách tất cả file trong commit mình chọn

git ls-tree --name-only -r <commitHash>
git ls-tree --name-only 9dea936:"Tài nguyên hỗ trợ/Công việc thời vụ kiếm tiền nhanh"
  • Bỏ -r để không recurse

Đọc nội dung một file trong một commit cũ

git show <commitHash>:/path/to/file

Nếu muốn mở trong vim thì:
git show <commitHash>:/path/to/file | vim -

Nhược điểm của việc này là vì vim đọc trực tiếp từ stdin, nên không biết định dạng file là gì để mà tô màu. Có thể sửa việc này bằng:
git show <commitHash>:/path/to/file | vim -c 'set filetype=python' -

Tìm commit sớm nhất chứa file

git log --follow --diff-filter=A --find-renames=40% --pretty=reference -- "**Thông tin cho đại lý.md" 

Khởi tạo repo mới và đẩy lên GitHub

$repo = 'QuaCau-TheSphere/CA-Bao-hiem'
git init
git add -A
git commit -m "init"

gh repo create --public $repo
$url = gh repo view $repo --json url --jq '.url'
git remote add origin $url 
git push -u origin main

Mẹo dùng Git với Obsidian
Xem thêm:: Các lỗi Git thường gặp, Git tag
Xem thêm:: GitHub - git-tips/tips: Most commonly used git tips and tricks.