Skip to content

Discarding and Resetting

Every tool in this guide so far has added or moved things. This chapter is about taking them away: throwing a file's changes in the bin, and moving a branch backwards over its own history. Both are one key away in lazygit, both are guarded by the most honest menus in the program, and both are where chapter 1's rule earns its keep. The outcome: you can discard exactly the changes you mean — staged, unstaged, or both — and you can name what mixed, soft and hard resets each do to your branch, your index and your files, before you ever choose one.

Discarding a file's changes: d

Select a changed file in the Files panel and press d. A menu opens titled Discard changes (transcript lazygit-lab/transcripts/t07-discard-and-reset.txt):

  • x — Discard all changes
  • u — Discard unstaged changes
  • Cancel

And under the menu, a description box speaks for the highlighted choice, in plain words, naming the actual file:

Discard both staged and unstaged changes in 'summer-walk.txt'.

That box is the design decision this chapter exists to praise. On the command line, git checkout -- <file> and git restore --staged differ by a flag you must remember under pressure; here the program states the consequence, with your filename in it, before you confirm it. Read the box. It has never once, in the lab's sessions, said anything other than exactly what then happened.

The lab chose Discard all changes on summer-walk.txt. The command log recorded git checkout -- summer-walk.txt, and afterwards git status confirmed it: the modification was gone. Equally instructive is what did not happen: the staged shopping.txt and the untracked winter-walk.txt, rows away on the same screen, were untouched. Discarding in lazygit is per-selection — the file, the folder row, the commit in focus — and the description box names the selection it means.

What discard cannot do is come back. A discarded modification was never a commit, so it is in no diary and no object store; chapter 8's boundary applies at full force. The menu is the safety net. If there is any chance the change matters — a paragraph you might want, a fix half-proved — the cheap moves come first: commit it to a scratch branch (chapters 5 and 6), or stash the work away (chapter 9), where it stays recoverable. Then discard with a clear conscience.

For a staged file, "Discard unstaged changes" is the gentle option and "all" the thorough one. For an untracked file the stakes rise a level: there is no committed version to fall back to, so discarding there means deleting the file itself — the documentation's account, flagged in criteria.md, as the lab discarded tracked changes only.

Resetting a branch: D and g

To reset is to move a branch's label to another commit — usually an earlier one — and decide what happens to the difference. Two keys offer it:

  • D in the Files panel (its hint-bar entry is "Reset...") opens reset choices aimed at the current commit.
  • g opens Reset to @{upstream} — the same choice aimed at the commit your branch tracks on its remote (chapter 12), the "throw away my local lead and match the server" move.

Both present the same three hardnesses, each described in the menu's lower box (transcript t07 has the upstream menu, captured in full):

  • m — Mixed reset (git reset --mixed <target>). The branch moves; the index is cleared to match the target; your working files are not touched. The commits' changes reappear as unstaged modifications. This is git's default reset, and the one for "I committed too soon — give me the work back to re-decide."
  • s — Soft reset (git reset --soft <target>). The branch moves; index and files both keep everything. The commits' changes reappear staged, ready to be committed again as something better. This is the reset chapter 8's undo uses.
  • h — Hard reset (git reset --hard <target>). The branch moves, and index and files are made to match the target. Committed work in between is stranded to the reflog (chapter 8 can fetch it back); uncommitted work in the way is destroyed, silently and completely.

The lab opened these menus and read them but executed its resets through chapter 8's undo instead — the same soft reset, arriving with its target already chosen. The mixed and hard forms are therefore described here from the menus themselves and git's documentation, and criteria.md files them accordingly.

The habit this chapter teaches

Discard and hard reset are the two operations in the whole program that can make work unrecoverable, and lazygit knows it: menus before action, plain descriptions, confirmations behind them. Your half of the bargain is chapter 1's rule, one more time, in its sharpest form: before you throw away, ask whether it was ever committed. If it was, proceed in peace — the diary holds it. If it was not, the menu in front of you is the only moment the work will ever be described so clearly again.