- vừa được xem lúc

Tổng hợp các câu lệnh GIT thường dùng GIT#1

0 0 15

Người đăng: Thống PM

Theo Viblo Asia

Git Bash Commands Cheat Sheet

Setup

  1. git config --global user.name “[firstname lastname]” # Set a name that is identifiable for credit when review version history
  2. git config --global user.email “[valid-email]” # Set an email address that will be associated with each history marker
  3. git config --global color.ui auto # Set automatic command line coloring for Git for easy reviewing
  4. git config --global --list # List all Git configuration settings

Repository Initialization

  1. git init # Initialize a new Git repository
  2. git clone <url> # Initialize a new Git repository

Stage & Snapshot

  1. git status # Check the status of your repo
  2. git add <file> # Add a file to the staging area
  3. git reset <file> # Remove a file from the staging area
  4. git commit -m "<message>" # Commit changes with a message

Inspect & Compare

  1. git log # View commit history
  2. git log --oneline # View commit history in compact format
  3. git log --oneline -n <amount> # View commit history in compact format
  4. git log <branch1> <branch2> # show the commits on branch1 that are not on branch2
  5. git log --stat -M #
  6. git diff # Show changes between working directory and the last commit
  7. git diff <branch1> <branch2> # Show changes between two branches
  8. git show <commit> # Show changes made in a specific commit

Branch

  1. git status # Check the status of your repo
  2. git branch # List all branches
  3. git branch <branch> # Create a new branch
  4. git checkout <branch> # Switch to a branch
  5. git checkout -b <branch> # Create and switch to a new branch
  6. git branch -d <branch> # Delete a branch
  7. git branch -r # List remote branches
  8. git branch -a # List local and remote branches
  9. git branch -u <upstream-branch> # Set upstream branch for the current branch
  10. git branch -m <old-name> <new-name> # Rename a branch
  11. git branch --merged # List branches that have been merged into the current branch
  12. git branch --no-merged # List branches that have not been merged into the current branch

Merge

  1. git merge <branch> # Merge changes from different branches
  2. git merge --abort # Abort an ongoing merge operation
  3. git merge --squash <branch> # Squash the commits from a branch into a single commit
  4. git merge --no-ff <branch> # Merge with a merge commit even if it's a fast-forward merge

Rebase

  1. git rebase <branch> # Apply any commits of current branch ahead of specified one
  2. git rebase --abort # Abort an ongoing rebase operation
  3. git rebase --continue # Continue a paused rebase operation
  4. git rebase --skip # Skip a conflicting commit during rebase

Cherry-pick

  1. git cherry-pick <commit> # Apply a specific commit
  2. git cherry-pick --continue # Continue a paused cherry-pick operation
  3. git cherry-pick --abort # Abort an ongoing cherry-pick operation

Undoing Changes

  1. git reset # Reset staging area to match the last commit
  2. git reset <file> # Remove a file from the staging area
  3. git reset --hard # Discard all changes since the last commit
  4. git reset --hard [commit] # Clear staging area, rewrite working tree from specified commit

Remote Repositories

  1. git remote add origin <url> # Connect local repo to remote
  2. git push -u origin <branch> # Push changes to remote branch
  3. git pull # Pull changes from remote repo
  4. git clone <url> # Clone a remote repository
  5. git remote -v # List remote connections
  6. git remote rm <remote> # Remove a remote connection
  7. git fetch # Fetch updates from remote repo without merging
  8. git remote show <remote> # Show details about a remote repository
  9. git remote rename <old-name> <new-name> # Rename a remote repository
  10. git push --tags # Push all tags to remote repository
  11. git push --force # Force-push changes to the remote repository
  12. git push origin --delete <branch> # Delete a remote branch
  13. git pull --rebase # Pull and rebase the current branch
  14. git fetch # Fetch updates from all remote repositories
  15. git fetch --all # Fetch updates from remote repo
  16. git remote update # Update remote-tracking branches

Stashing (Temporary Commits)

  1. git stash # Save changes for later
  2. git stash list # List stashed changes
  3. git stash apply # Apply stashed changes
  4. git stash drop # Remove a stash
  5. git stash pop # Apply and remove the latest stash
  6. git stash branch <branch> # Create a new branch and apply a stash
  7. git stash save "<message>" # Save changes with a custom stash message
  8. git stash clear # Remove all stashed changes
  9. git stash apply <stash> # Apply a specific stash
  10. git stash drop <stash> # Remove a specific stash

Bình luận

Bài viết tương tự

- vừa được xem lúc

Đặt tên commit message sao cho "tình nghĩa anh em chắc chắn bền lâu"????

. Lời mở đầu. .

1 1 701

- vừa được xem lúc

Tập hợp những câu lệnh GIT hữu dụng

Dưới đây là một vài ví dụ về các câu lệnh Git mà tôi thường dùng. git config --global user.name "John Doe". git config --global user.

0 0 55

- vừa được xem lúc

Cấu hình CI/CD với Github (phần 2): Trigger một work flow

Events trigger. Bạn có thể cấu hình cho workflows chạy khi có một sự kiện nào đó xảy ra trên GitHub, theo một lịch có sẵn hoặc cũng có thể là một sự kiện nào đó xảy ra ngoài GitHub.

0 0 70

- vừa được xem lúc

Cấu hình CI/CD với Github (phần 1): Một ít lý thuyết

CI/CD là gì. Về mặt khái niệm là vậy nhưng về mặt triển khai thì CI/CD là quá trình tự động thực hiện các quá trình build, test, release, deploy khi có các trigger như commit/merge code lên một branch định sẵn hoặc có thể là tự động chạy theo một lịch cố định.

0 0 118

- vừa được xem lúc

Giới thiệu về Git LFS

. Git LFS là gì . Git LFS làm điều này bằng cách thay thế các tệp lớn trong repo của bạn bằng một con trỏ nhỏ.

0 0 29

- vừa được xem lúc

Git workflow được Google và Facebook sử dụng có gì hay ho

Với developer thì Git hẳn là công cụ rất quen thuộc và không thể thiếu rồi. Thế nhưng có mấy ai thực sự hiểu được Git.

0 0 66