免費轉換器
Git 指令 速查表
全面的 Git 指令速查表。搜尋 80+ 個必備 Git 指令,附帶範例、說明和一鍵複製功能。
git config --global user.name
Set the global username for commits
範例:
git config --global user.name "Your Name"git config --global user.email
Set the global email for commits
範例:
git config --global user.email "[email protected]"git config --list
List all Git configuration settings
範例:
git config --listgit config --global core.editor
Set the default text editor for Git
範例:
git config --global core.editor "vim"git init
Initialize a new Git repository in the current directory
範例:
git init my-projectgit clone
Clone a remote repository to your local machine
範例:
git clone https://github.com/user/repo.gitgit clone --depth
Shallow clone with limited history
範例:
git clone --depth 1 https://github.com/user/repo.gitgit add
Stage a specific file for the next commit
範例:
git add src/index.jsgit add .
Stage all modified and new files in the current directory
範例:
git add .git add -p
Interactively stage parts (hunks) of changed files
範例:
git add -pgit status
Show the working tree status (staged, unstaged, untracked)
範例:
git statusgit status -s
Show a compact status summary
範例:
git status -sgit diff
Show unstaged changes between working tree and index
範例:
git diff src/app.jsgit diff --staged
Show staged changes that will go into the next commit
範例:
git diff --stagedgit restore
Discard changes in the working directory
範例:
git restore src/index.jsgit restore --staged
Unstage a file (remove from staging area)
範例:
git restore --staged src/index.jsgit rm
Remove a file from the working tree and index
範例:
git rm old-file.txtgit mv
Move or rename a file and stage the change
範例:
git mv oldname.js newname.jsgit commit -m
Record staged changes with a commit message
範例:
git commit -m "feat: add login page"git commit -am
Stage all tracked files and commit in one step
範例:
git commit -am "fix: correct typo in README"git commit --amend
Modify the most recent commit (message or content)
範例:
git commit --amend -m "Updated commit message"git log
Show the commit history for the current branch
範例:
git log --oneline --graphgit log --oneline
Show compact one-line commit history
範例:
git log --oneline -20git log --author
Filter commit history by author
範例:
git log --author="Alice" --onelinegit log --since
Show commits after a given date
範例:
git log --since="2024-01-01" --onelinegit show
Show details of a specific commit
範例:
git show abc1234git diff HEAD
Show all changes since the last commit
範例:
git diff HEADgit shortlog
Summarize commit history grouped by author
範例:
git shortlog -sngit branch
List all local branches
範例:
git branch -agit branch <name>
Create a new branch at the current commit
範例:
git branch feature/logingit branch -d
Delete a merged local branch
範例:
git branch -d feature/logingit branch -D
Force-delete a branch regardless of merge status
範例:
git branch -D old-branchgit branch -m
Rename the current branch
範例:
git branch -m new-branch-namegit checkout
Switch to an existing branch
範例:
git checkout maingit checkout -b
Create and switch to a new branch
範例:
git checkout -b feature/new-uigit switch
Switch to an existing branch (modern syntax)
範例:
git switch maingit switch -c
Create and switch to a new branch (modern syntax)
範例:
git switch -c feature/api-v2git merge
Merge a branch into the current branch
範例:
git merge feature/logingit merge --no-ff
Merge with a merge commit even if fast-forward is possible
範例:
git merge --no-ff feature/logingit rebase
Reapply commits on top of another branch
範例:
git rebase maingit rebase -i
Interactive rebase to squash, reorder, or edit commits
範例:
git rebase -i HEAD~3git remote -v
List remote connections with their URLs
範例:
git remote -vgit remote add
Add a new remote repository connection
範例:
git remote add origin https://github.com/user/repo.gitgit remote remove
Remove a remote connection
範例:
git remote remove origingit remote set-url
Change the URL of an existing remote
範例:
git remote set-url origin [email protected]:user/repo.gitgit fetch
Download objects and refs from a remote without merging
範例:
git fetch origingit fetch --all
Fetch from all remotes
範例:
git fetch --allgit pull
Fetch and integrate changes from a remote branch
範例:
git pull origin maingit pull --rebase
Pull and rebase instead of merge
範例:
git pull --rebase origin maingit push
Upload local commits to a remote branch
範例:
git push origin maingit push -u
Push and set upstream tracking branch
範例:
git push -u origin feature/logingit push --force-with-lease
Force push safely (fails if remote has new commits)
範例:
git push --force-with-lease origin feature/logingit push --delete
Delete a remote branch
範例:
git push origin --delete old-branchgit stash
Temporarily save uncommitted changes to a stack
範例:
git stash push -m "WIP: half-done feature"git stash pop
Apply the most recent stash and remove it from the stack
範例:
git stash popgit stash apply
Apply a stash without removing it from the stack
範例:
git stash apply stash@{0}git stash list
List all stashed changes
範例:
git stash listgit stash drop
Remove a specific stash entry
範例:
git stash drop stash@{1}git stash clear
Remove all stashed entries
範例:
git stash cleargit stash show
Show a summary of changes in a stash
範例:
git stash show -p stash@{0}git stash branch
Create a branch from a stash
範例:
git stash branch feature/stashed stash@{0}git tag
List all existing tags
範例:
git tag -l "v1.*"git tag <name>
Create a lightweight tag at the current commit
範例:
git tag v1.0.0git tag -a
Create an annotated tag with a message
範例:
git tag -a v1.0.0 -m "Release version 1.0.0"git tag -d
Delete a local tag
範例:
git tag -d v1.0.0-betagit push --tags
Push all local tags to the remote
範例:
git push origin --tagsgit push origin <tag>
Push a specific tag to the remote
範例:
git push origin v1.0.0git describe
Show the most recent tag reachable from the current commit
範例:
git describe --tags --abbrev=0git reset --soft
Move HEAD back, keep changes staged
範例:
git reset --soft HEAD~1git reset --mixed
Move HEAD back, unstage changes (default)
範例:
git reset HEAD~1git reset --hard
Move HEAD back and discard all changes
範例:
git reset --hard HEAD~1git revert
Create a new commit that undoes a previous commit
範例:
git revert abc1234git revert --no-commit
Revert changes without creating a commit yet
範例:
git revert --no-commit abc1234git clean -fd
Remove untracked files and directories
範例:
git clean -fdgit clean -n
Dry run: show what would be removed by clean
範例:
git clean -ngit checkout -- <file>
Restore a file to the last committed state
範例:
git checkout -- src/index.jsgit cherry-pick
Apply a specific commit from another branch
範例:
git cherry-pick abc1234git cherry-pick -n
Cherry-pick without committing (stage only)
範例:
git cherry-pick -n abc1234git bisect start
Start a binary search to find a bug-introducing commit
範例:
git bisect start && git bisect bad && git bisect good v1.0git bisect good/bad
Mark a commit as good or bad during bisect
範例:
git bisect goodgit reflog
Show the history of HEAD and branch tip movements
範例:
git reflog --date=isogit submodule add
Add a repository as a submodule
範例:
git submodule add https://github.com/user/lib.git libs/libgit submodule update
Initialize and update all submodules
範例:
git submodule update --init --recursivegit worktree add
Check out a branch in a new working directory
範例:
git worktree add ../hotfix hotfix/criticalgit blame
Show who last modified each line of a file
範例:
git blame -L 10,20 src/app.jsgit archive
Create a zip/tar archive of a tree
範例:
git archive --format=zip HEAD > release.zip