The files panel reflects your git workspace while working on changes locally in your repository. It offers staging, committing, stashing, and clearing your local workspace. This post will introduce all details of the files panel below.
Series index
- Introduction to lazygit
- Deep dive: status panel
- You're here: Deep dive: files panel
- Deep dive: branches panel
- Deep dive: commits panel
- Deep dive: stash panel
- Use-case: backporting with rebase onto
Overview
The files panel is the second panel from the top and has the hotkey 2.
In the above screenshot, the files panel shows any changes in your git workspace. These might be staged, unstaged, or untracked changes. The characters stand for Untracked(??), Added (A), Deleted(D), or Modified(M). As with git status, the colors stand for unstaged (red) and staged (green).
Let's go through the individual tasks you can achieve with it.
Staging files
While it is active, use up and down arrows or j and k to navigate between entries. Use the space key ␣ to toggle the state of the selected file. Green equals staged, red equals unstaged/untracked.
To (un)stage all files, use a.
Editing files
You can open o and edit e each file entry using your defined editor.
Committing
To commit the staged files in a quick manner, hit lowercase c. This will open a dialog-style input within lazygit. To perform the commit, hit enter.
If you need newlines, you need to use tabs to break lines.
If you like me prefer to use your $EDITOR to commit, e.g., to get proper formatting hints, use uppercase C instead. This will
Stashing files
You can stash your entire worktree with s. Through a menu with uppercase S, you can also stash just the staged tree.
Discarding changes
To discard changes from the worktree, press d. This will open a menu to confirm discarding either all, or just the staged changes.
Hit uppercase D to open a separate menu with some lesser used options to clean or reset the working tree.
Reset from upstream
A bit confusingly, you can reset your tree to a remote tracking branch from the files section with g. This will open a menu to use a soft, hard, or mixed reset to the upstream tracking branch.
For me, this is very useful when I force pushed and pick up work on a different device.
Refresh and fetch upstream
You can refresh the files section with r. This is due to lazygit polling the filesystem for changes, so entries in this section will be delayed by a few seconds.
To fetch changes from the remote, use f instead.
Staging lines or hunks from files
In many cases, you will not want to commit entire files, but extract some logically connected lines together and commit changes separately.
When you have selected an individual file, the right hand side of lazygit will show its diff. You can move into that diff with enter.
In that section, you can stage individual lines with space ␣. Move between the lines with ↓/↑ and j/k fashion as the files section.
To move between hunks, use left and right arrows →/←.
To select the entire hunk, use a. To visually select multiple lines, use v and the movement keys.
You can also delete parts of staged or unstaged changes with d.
In the files section, this file will now be shown as MM
to signal that it is partially staged.
Submodules tab
In the same panel, next to the files section, there also is the submodules panel. You can move to it with the default key binding ].
I don't really use submodules, so I can't comment on its uses. Just open the help menu with ?
and explore!
Next post in series