Git Command Reference

Search Git by task in plain words, such as undo the last commit or find who changed a line, and get the exact command with what it does and when to be careful.

Działa w Twojej przeglądarce. Twoje pliki nigdy nie opuszczają urządzenia. Zobacz, jak to sprawdzić

…

Jak to zrobić

  1. 1
    Search by task

    Type what you want to do.

  2. 2
    Or pick a section

    Browse by area.

  3. 3
    Check warnings

    Note commands that rewrite history.

  4. 4
    Copy the command

    Replace placeholders in angle brackets.

  5. 5
    Try it safely

    Test on a branch or a clone first.

  6. 6
    Save the sheet

    Download the CSV for your team.

O tym narzędziu

Git has hundreds of commands and options, and the right one for a task is rarely obvious: is it reset, restore or revert? This reference is organised by what you want to do rather than by command name. Search in plain words, such as undo, rename branch, stash or who changed, or pick a section: set up, start, daily work, history, branches, merging, remote, stash, undo, tags, inspect and advanced. Each entry gives the exact command, what it does, and a warning when it rewrites history or deletes work, so you know which commands are safe on a shared branch and which are not. Undo recipes cover the common emergencies: undoing the last commit while keeping the changes, throwing away local changes, getting back to where you were before a bad rebase, and recovering "lost" commits with the reflog. Download the whole reference as CSV for your team wiki.

Safe and unsafe commands

Commands that rewrite published history (commit --amend, rebase, reset --hard, push --force) are fine on your own local branches but cause trouble for anyone who already pulled your commits. On shared branches, prefer git revert, which adds a new commit undoing an old one. When you must force-push, use --force-with-lease, which refuses if someone else pushed in the meantime.

The safety net

git reflog records every position HEAD has been at, including commits that no longer appear in any branch. If a reset or rebase went wrong, find the old position in the reflog and git reset --hard to it. Unreachable commits are kept for weeks before garbage collection.

reset, restore and revert

- git restore changes files in your working folder or staging area. - git reset moves the current branch to another commit (soft keeps changes staged, mixed keeps them unstaged, hard discards them). - git revert makes a new commit that undoes an old one, without rewriting history.

Useful less-known commands

- git log -S "text" finds when a piece of code appeared or disappeared. - git bisect finds the commit that introduced a bug by binary search. - git worktree checks out another branch in a second folder without stashing. - git switch and git restore replace the overloaded git checkout.

Limits

This reference covers everyday and intermediate Git; plumbing commands, hooks and server administration are out of scope. It is not an official Git manual; check git help for every option. Options follow Git 2.40 and later; some are missing in older versions.

Przykład z rozwiązaniem

Searching "undo commit" lists git reset --soft HEAD~1 (keep changes staged), --mixed (keep them unstaged), --hard (discard them, flagged), git revert for shared branches, and git reset --hard ORIG_HEAD to undo a bad merge or rebase.

W skrócie

Najczęstsze pytania

How do I undo the last commit but keep my changes?

git reset --soft HEAD~1 keeps them staged; --mixed keeps them unstaged.

How do I undo a commit already pushed?

Use git revert, which adds an undo commit without rewriting history.

I lost commits after a reset. Can I get them back?

Usually yes: find them in git reflog and reset or branch to them.

What is the difference between merge and rebase?

Merge keeps both histories with a merge commit; rebase replays your commits on top for a linear history.

Can I download the reference?

Yes, as CSV.

Which Git version does it assume?

Git 2.40 or later; most commands work in older versions too.

Całkowicie za darmoBez opłat i rejestracji
Pliki zostają prywatneWszystko działa w Twojej przeglądarce
Łatwo w Twoim językuDostępne w wielu językach