The commits panel lists recent commits and provides extensive rebasing operations on them. It also allows to work with the git reflog, a powerful way to undo certain git operations.
- Introduction to lazygit
- Deep dive: status panel
- Deep dive: files panel
- Deep dive: branches panel
- You're here: Deep dive: commits panel
- Deep dive: stash panel
- Use-case: backporting with rebase onto
The commits panel is the fourth panel from the top and thus has the hotkey 4.
In the above screenshot, the panel shows all recent commits of the checked out branch.
The commits panel operates on both the commits themselves and on the objects it contains. On the second tab, it provides an interface to the git reflog.
It offers a variety of actions in these areas, let's go through them.
Working with commits
Navigating the commit(s)
As with all other panels, navigate through the commits using ↓ and ↑.
To display the contents of a commit, press ↵. This will show a list of files that have been changed, and the respective diff on the right-hand side. Pressing enter again will focus the diff.
This opens a whole word of editing commits and patches that we'll be looking into in a different section.
Here are some of my common actions I do in that panel:
With staged changes in your files panel, you can amend it to any commit you selected it with A. Amending commits earlier than the latest commit will result in lazygit doing a rebase for you.
Squash and fixup
A lot of fun can be had in the panel with its rebasing capabilities.
Squash a commit down into the next neighbor (keeping its commit message) with s. Similarly, fixup f folds the commit down, discarding the commit's log message.
To create a new fixup commit for the selected commit, using the stages changes, use F.
This will keep the new commit until you manually rebase with
--autosquash, or you can use S to squash all fixup commits above the selected commit.
Lazygit provides an easy way to move and reorder commits by doing a rebase for you. Keep in mind that this might result in conflicts you need to resolve.
To move a commit down, use CTRL+j. To move up, use CTRL+k.
Editing commit messages
You can edit the commit message with lazygit with r, or with your external editor using uppercase R.
To select one or multiple commits for cherry picking, use uppercaseC. You can then switch to another branch and apply them with v.
To add a new commit that reverts the given commit, run t.
You can delete the commit message with lazygit with d. A confirmation will be shown. Note that this will also result in a rebase if you're not deleting the top-most commit.
Rebasing onto another branch (v0.40+)
In lazygit release 0.40,
rebase --onto support was introduced.
To choose a base commit for the rebasing option, select it in the commits panel and press Shift+b. The panel visually changes to show arrows on the first commit that will not be included in the rebase. All commits above it will be part of the rebase.
You can then rebase as normal from the branches panel.
Commit files and patches
To show the contents of a commit, use the enter key ↵. It replaces the panel with the contents of that commit, showing the files changed.
It behaves very similarly as the files section with a few interesting differences handling the commit's patches. Navigate the files ↓ and ↑ to change the focused file you work on.
When you entered the committed files of a commit and navigated to a file, press ↵ again to navigate to the selected file. This moves the focus to the main panel. Open the selected file with e or open it with o.
Deleting a change
With a file selected, you can delete the entire changes to that file with d. A confirmation dialog will be shown before the rebase takes place.
Creating custom patches
This is probably the most stunning feature of this entire panel. You can extract, remove, or reverse patches created from changes within this commit.
This warrants its own post later on, but we're briefly looking at it here. Think of a custom patch as a separate staging area, that you can add or remove files and hunks to.
To toggle an entire file for the custom patch, use ␣. When within a file in the main section, add lines or hunks to the custom patch in the same fashion as described in the files panel.
The custom patch you're building is shown in the main section as a separate panel.
When you're done building the custom patch, type CTRL+p to open the custom patch menu.
- Reset patch cancel the custom patch, resetting any selections you've made
- Apply patch Run
git applywith the patch here (this won't do anything if the patch is from this commit)
- Apply patch in reverse Run
git apply --reversewith the patch here
- Remove patch from original commit Removes the selected changes from this commit and discards it! (Results in rebase)
- Move patch into new index Removes the selected changes from this commit and adds it to the stash (Results in rebase)
- Move patch into new commit Removes the selected changes from this commit and adds a new commit with the changes. The commit message will be "Split from <this commit>"
Move to the reflog tab with ]. It gives you a representation of the reflog similar to the commits panel itself.
From here, you can navigate ↓ and ↑ and restore an older version of the reflog with the space key ␣.
Next post in series