| English | 中文 |
git init
git clone <url>
git status
git log --oneline --decorate
git add <file>
git commit -m "docs: add git basics"
git fetch
git pull --rebase
git push
<integration-branch> is the team’s actual integration branch name. Common values include main, master, and develop. Confirm it from repository rules before switching; do not treat main as a fixed default.
git switch -c feat/my-task
git branch --show-current
git switch <integration-branch>
git branch
git restore overwrites the Working Tree for the named path. Before running it, confirm that the path belongs to you and that its current version may be discarded:
git status --porcelain
git diff -- <owned-path>
git restore --worktree -- <owned-path>
To unstage the named path while keeping its Working Tree edit:
git restore --staged -- <owned-path>
To make a reverse commit for an already committed change:
git revert <commit-sha>
git restore --staged adjusts only the Index and keeps the Working Tree edit; git revert creates a reverse commit for an already committed change.
git status to understand the current state.git add and git commit to complete one local commit.git switch -c to create a task branch.git diff to check changes before committing.git push to push the branch and create a PR.git restore to undo local changes.First check for staged, unstaged, or untracked content that must be retained, and only preview untracked files:
git status --porcelain
git diff
git diff --cached
git clean -nd
If git status --porcelain prints anything, stop and do not run git reset --hard or git clean. git clean -nd only lists candidate paths; it does not establish that they may be deleted.
After confirming ownership and authorization to dispose of local edits, verifying the reset target, and confirming remote permission, branch rules, and collaborator impact, the owner can decide whether to use git reset --hard, git clean -fd, or git push --force. They can respectively discard tracked edits, delete untracked paths, and rewrite remote history.
If you just want to undo ordinary workspace changes, prioritize learning Undo Anything.