Skip to content

Staging changesλ︎

Regularly staging changes provides an additional safety net as you work towards a meaningful change.

Magit enables very fine grain selection when staging changes. A file, a hunk or even a specific line can be staged and unstaged. This makes it very easy to create clean commits.

s to stage the current file, hunk or selected region. Multiple files can be staged by selecting the filenames. S stages all the untracked files and Unstaged changes.

u to unstage the current file, hunk or selected region in the staged changes section. U to unstage everything (from anywhere in the Magit Status buffer).

Spacemacs Magit Status - staging files

Tab to expand a section, eg. a file expands to git hunks, hunks expand to lines in the hunk. Shift+Tab to collapse a section.

[ to jump down from section to section, ] to jump back up.

v to visually select one or more filenames or lines to stage or unstage.

Visual select within hunk boundary

Selecting lines to stage or unstage only works within the Git hunk boundary. The action fails if lines are selected from more than one hunk.

Hiding white-space in Magit diff

D in the Magit Status buffer to change how diffs are rendered

-b ignore whitespace changes

-w to ignore all whitespace

Renamed filesλ︎

s to stage the deleted file (previous file name) and the new file name (in untracked files). Magit status should show the file as renamed, unless the contents was significantly changed.

x on a file name in Magit Status buffer will delete that file. A prompt will show in the mini-buffer to confirm you want to 'Trash' the file.

v enters visual select mode, j and k can be used to select multiple files. x deletes all the selected files, with a mini-buffer prompt to confirm.

Magit staging and commit basicsλ︎