DevToolBox免费
博客

Lazygit 完全指南 2026:终端 Git UI — 交互式 Rebase、暂存与工作流

25 分钟阅读作者 DevToolBox Team

TL;DR

Lazygit 是一个免费开源的终端 Git UI,让交互式变基、部分暂存、冲突解决和摘取提交等复杂操作只需按一个键即可完成。它可以在任何终端环境中运行,原生集成 Neovim 和 VS Code,并通过 config.yml 完全可定制。在 2026 年,它仍然是不离开命令行管理 Git 仓库的最快方式。

Key Takeaways

  • Lazygit 在终端中提供功能完整的 Git GUI,包含 5 个面板:状态、文件、分支、提交和贮藏
  • 交互式变基直观可视化:通过单键操作重新排序、压缩、修复、编辑和删除提交
  • 使用空格键暂存单独的行和区块,轻松创建精确的原子提交
  • 冲突解决使用并排视图,只需一个按键即可选择更改
  • config.yml 中的自定义命令让你定义绑定到任意键的项目特定 Git 工作流
  • 通过 lazygit.nvim 原生集成 Neovim,通过终端集成 VS Code

Table of Contents

  1. 什么是 Lazygit 以及为什么它很重要
  2. Lazygit vs GitKraken vs Fork vs SourceTree vs tig
  3. 安装
  4. 界面概览:5 个面板
  5. 键盘快捷键速查表
  6. 暂存:文件、区块和行
  7. 提交:约定式提交、修改、修复
  8. 分支:创建、合并、变基、摘取
  9. 交互式变基
  10. 贮藏
  11. 冲突解决
  12. 远程操作
  13. 工作树和子模块
  14. 自定义命令和键绑定
  15. 编辑器集成:Neovim 和 VS Code
  16. 过滤、搜索和二分查找
  17. 补丁管理
  18. 主题和自定义
  19. 大型仓库性能
  20. 常见工作流
  21. 高级用户技巧
  22. 常见问题

Git 是现代软件开发的支柱,但其命令行界面对于复杂操作仍然出了名的难用。交互式变基、部分暂存、冲突解决和摘取提交都需要记住晦涩的标志和多步骤序列。Lazygit 通过将 Git 的全部功能包装在直观的终端用户界面中来解决这个问题。

Lazygit 由 Jesse Duffield 于 2018 年创建,已发展成为 GitHub 上最受欢迎的开发者工具之一,拥有超过 55,000 颗星。它运行在 macOS、Linux 和 Windows 上,不需要 GUI 框架,可以通过 SSH 工作。在 2026 年,凭借其成熟的插件系统、自定义命令和深度编辑器集成,Lazygit 已成为面向终端的开发者的标准 Git 界面。

什么是 Lazygit 以及为什么它很重要

Lazygit 是一个用 Go 编写的基于终端的 Git 用户界面。它通过五个交互式面板展示你的仓库状态:状态、文件、分支、提交和贮藏。每个 Git 操作——从暂存单独的行到执行交互式变基——都可以通过单键快捷方式访问,无需输入任何 Git 命令。

为什么终端 Git UI 很重要?GitKraken 和 Fork 等 GUI 工具很强大,但需要专用应用程序,消耗大量资源,且无法通过 SSH 运行。原生 Git CLI 是通用的,但对复杂操作不友好。Lazygit 占据了最佳位置:终端的速度和可移植性加上完整的可视化反馈。

  • 随处运行:本地终端、SSH、tmux、Docker 容器、WSL
  • 除 Git 本身外零依赖 — 单二进制文件分发
  • 键盘驱动:每个操作只需一次按键
  • 完整的 Git 功能覆盖:变基、摘取、二分查找、工作树、子模块、补丁
  • 通过 config.yml 完全可定制的键绑定、主题和自定义命令
  • 活跃开发,频繁发布,维护者响应迅速

Lazygit vs GitKraken vs Fork vs SourceTree vs tig

每个 Git 客户端适合不同的工作流。此比较帮助你选择合适的工具。

FeatureLazygitGitKrakenForkSourceTreetig
TypeTerminal UIDesktop GUIDesktop GUIDesktop GUITerminal UI
PriceFree (MIT)\$4.95/mo Pro\$49.99 one-timeFreeFree (GPL)
PlatformmacOS/Linux/WindowsmacOS/Linux/WindowsmacOS/WindowsmacOS/WindowsmacOS/Linux/Windows
SSH SupportYes (native)NoNoNoYes (native)
Interactive RebaseExcellent (visual)GoodGoodBasicNone
Line-level StagingYesYesYesYesNo
Conflict ResolutionBuilt-in side-by-sideBuilt-in 3-wayBuilt-in 3-wayExternal toolNone
Startup Time<100ms3-5 seconds1-2 seconds2-4 seconds<50ms
Memory Usage~15MB~500MB (Electron)~200MB~300MB~5MB
Custom CommandsYes (config.yml)NoNoCustom actionsNo
Neovim Integrationlazygit.nvimNoneNoneNoneNone
WorktreesYesNoNoNoNo

安装

Lazygit 以单一二进制文件分发。使用你喜欢的包管理器安装或从源码构建。

macOS (Homebrew)

brew install lazygit

# Verify installation
lazygit --version

Ubuntu / Debian (apt)

# Add the PPA repository
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_\${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf lazygit.tar.gz lazygit
sudo install lazygit /usr/local/bin

Windows (Scoop)

scoop install lazygit

# Or with Chocolatey
choco install lazygit

Go Install

go install github.com/jesseduffield/lazygit@latest

Docker

# Run lazygit in a Docker container with your repo mounted
docker run --rm -it \
  -v /path/to/repo:/repo \
  -w /repo \
  lazyteam/lazygit:latest

Arch Linux

pacman -S lazygit

界面概览:5 个面板

在 Git 仓库中输入 lazygit 启动时,你会看到五个分屏排列的面板。每个面板通过 Tab 或数字键聚焦,面板内的操作根据上下文而变化。

状态面板(1)显示当前分支、远程跟踪状态和最近日志。文件面板(2)显示已暂存和未暂存的更改,类似 git status。分支面板(3)列出本地和远程分支,提供检出和合并选项。提交面板(4)显示提交日志,具有交互式变基功能。贮藏面板(5)管理你的贮藏条目并提供预览。

# Launch lazygit in the current repository
lazygit

# Panel Layout:
# +------------------+----------------------------------+
# | 1. Status        |                                  |
# +------------------+        Main Panel                |
# | 2. Files         |     (diff / staging view)        |
# +------------------+                                  |
# | 3. Branches      |                                  |
# +------------------+                                  |
# | 4. Commits       |                                  |
# +------------------+                                  |
# | 5. Stash         |                                  |
# +------------------+----------------------------------+

键盘快捷键速查表

Lazygit 完全由键盘驱动。以下是按上下文组织的最重要快捷键。

Global Navigation

KeyAction
Tab / Shift+TabSwitch between panels
1-5Jump to specific panel
h / lScroll left/right in sub-tabs
j / kMove up/down in list
?Show keybindings for current panel
xOpen action menu
/Filter current list
qQuit lazygit
@Open command log
zUndo last action
Ctrl+zRedo
+ / -Expand/collapse side panels

Files Panel

KeyAction
SpaceStage/unstage file
aStage/unstage all files
EnterOpen file in staging view (hunk/line staging)
cCommit staged changes
AAmend last commit
sStash changes
SStash options (staged only, untracked, etc.)
dDiscard changes in file
eOpen file in editor
oOpen file in default application
iAdd to .gitignore

Branches Panel

KeyAction
SpaceCheckout branch
nCreate new branch
dDelete branch
MMerge selected into current
rRebase current onto selected
RRename branch
fFetch
wCreate worktree

Commits Panel

KeyAction
EnterView commit diff
CCopy commit (for cherry-pick)
VPaste (cherry-pick) copied commits
sSquash commit into parent
fFixup commit into parent
dDrop commit
eEdit commit (start interactive rebase)
rReword commit message
Ctrl+j / Ctrl+kMove commit up/down (reorder)
gReset to this commit
tCreate tag at commit
bBisect: mark good/bad

暂存:文件、区块和行

Lazygit 最强大的功能之一是粒度暂存。在文件面板中,按空格键暂存或取消暂存整个文件。按 Enter 打开暂存视图,可以暂存单个区块甚至单独的行。

在暂存视图中,使用方向键在区块之间导航。按空格键暂存当前区块。按 v 进入行选择模式,然后使用方向键选择特定行,再按空格键只暂存这些行。这使得创建专注的原子提交变得非常简单。

# Staging workflow in lazygit:
#
# 1. Navigate to Files panel (press 2)
# 2. Press Enter on a file to open staging view
# 3. Use arrow keys to navigate between hunks
# 4. Press Space to stage a hunk
# 5. Press v to toggle line-selection mode
# 6. Select specific lines with arrow keys
# 7. Press Space to stage selected lines only
# 8. Press Escape to return to files panel
# 9. Press c to commit staged changes

提交:约定式提交、修改、修复

在文件面板中按 c 打开提交消息编辑器。输入消息后按 Enter 提交。对于约定式提交,直接输入前缀:feat: add user login 或 fix: resolve null pointer。

按 A 修改上一次提交(将暂存的更改添加到上一次提交)。在提交面板中按 shift+F 创建修复提交,它会在下次带有 autosquash 的交互式变基期间自动压缩到目标提交中。

# Conventional commit examples in lazygit:
# Press c, then type:
#   feat: add user authentication
#   fix: resolve login redirect loop
#   refactor: extract validation logic
#   docs: update API reference
#   chore: upgrade dependencies
#   test: add unit tests for auth module
#   perf: optimize database queries
#   ci: add GitHub Actions workflow

# Amend last commit: press A in Files panel
# Create fixup commit: press Shift+F on target commit in Commits panel
# Autosquash fixup commits: perform interactive rebase

分支:创建、合并、变基、摘取

在分支面板中按 n 从当前 HEAD 创建新分支。按空格键检出分支。按 M 将选定分支合并到当前分支。按 r 将当前分支变基到选定分支上。

摘取提交很直观:导航到提交面板,按 C 复制提交,切换到目标分支,按 V 粘贴(摘取)提交。你可以复制多个提交并一次性全部粘贴。

# Branch operations in lazygit:
#
# Create branch: press n in Branches panel -> type name -> Enter
# Checkout: press Space on branch
# Merge: select branch -> press M -> confirm
# Rebase: select branch -> press r -> confirm
#
# Cherry-pick workflow:
# 1. Go to Commits panel
# 2. Press C on commit(s) to copy
# 3. Switch to target branch (Branches panel -> Space)
# 4. Press V to paste (cherry-pick) the commits

交互式变基

交互式变基是 Lazygit 真正闪耀的地方。在提交面板中,按 e 从某个提交开始交互式变基。每个提交显示其变基操作,你可以用单键更改它们。

按 s 将提交压缩到下面的提交中。按 f 进行修复(压缩但不保留消息)。按 d 删除提交。按 e 编辑提交(暂停变基以便你进行更改)。使用 ctrl+j 和 ctrl+k 通过上下移动来重新排序提交。按 m 在变基期间更改提交消息。

# Interactive rebase actions in Commits panel:
#
# e  - edit: pause at this commit to amend
# s  - squash: merge into commit below, combine messages
# f  - fixup: merge into commit below, discard this message
# d  - drop: remove this commit entirely
# r  - reword: change commit message
# Ctrl+j - move commit down (later in history)
# Ctrl+k - move commit up (earlier in history)
#
# Example: squash last 3 commits into one
# 1. Press e on the commit 3 positions below HEAD
# 2. Press s on the 2nd commit
# 3. Press s on the 3rd commit
# 4. Edit the combined message
# 5. The rebase completes automatically

贮藏

在文件面板中按 s 贮藏所有更改。系统会提示你输入贮藏消息。按 S 打开贮藏选项,你可以选择只贮藏已暂存的更改、包含未跟踪的文件或保留索引。

在贮藏面板中,按空格键应用贮藏条目(保留贮藏),按 g 弹出(应用并删除),或按 d 删除贮藏条目。按 Enter 预览任何贮藏的内容后再应用。

# Stash operations:
#
# Files panel:
#   s     - stash all changes (prompted for message)
#   S     - stash options menu:
#           - Stash all changes
#           - Stash staged changes only
#           - Stash including untracked files
#           - Stash keeping index
#
# Stash panel:
#   Space - apply stash entry (keep in stash list)
#   g     - pop stash entry (apply and remove)
#   d     - drop stash entry (remove without applying)
#   Enter - preview stash contents before applying

冲突解决

当合并冲突发生时,Lazygit 在文件面板中高亮显示冲突文件。按 Enter 打开合并冲突视图,显示冲突的两侧。

在冲突视图中,按上下方向键在冲突标记之间导航。按左方向键选择传入的更改(theirs),按右方向键选择当前的更改(ours),或按 b 选择两者。解决文件中所有冲突后,按空格键标记为已解决并继续合并或变基。

# Conflict resolution in lazygit:
#
# 1. Conflicted files appear with red markers in Files panel
# 2. Press Enter on a conflicted file
# 3. The merge view shows both sides:
#    <<<<<<< HEAD (ours / current)
#    const name = "Alice";
#    =======
#    const name = "Bob";
#    >>>>>>> feature-branch (theirs / incoming)
#
# Navigation:
#   Up/Down  - move between conflict blocks
#   Left     - pick incoming (theirs)
#   Right    - pick current (ours)
#   b        - pick both
#   Space    - mark file as resolved after all conflicts handled

远程操作

按 P(大写)推送当前分支到远程。按 p(小写)拉取。按 f 获取所有远程。如果推送被拒绝,Lazygit 会提供使用 force push with lease 的选项,这比普通强制推送更安全,因为它会检查远程自你上次获取后是否已更新。

要管理多个远程,切换到分支面板内的远程子面板。在这里你可以添加、编辑和删除远程,以及从特定远程获取。

# Remote operations:
#
# P (uppercase) - Push to remote
# p (lowercase) - Pull from remote
# f             - Fetch all remotes
#
# If push is rejected (non-fast-forward):
#   Lazygit prompts: "Push rejected. Force push with lease?"
#   This runs: git push --force-with-lease
#   Safe because it checks remote hasn't been updated
#
# Managing remotes:
#   Navigate to Remotes sub-tab in Branches panel
#   n - add new remote
#   d - remove remote
#   e - edit remote URL

工作树和子模块

Lazygit 支持 Git 工作树,允许你同时在多个分支上工作,无需贮藏或切换。在分支面板中按 w 为选定分支创建新工作树。Lazygit 将在工作树目录中打开新实例。

对于子模块,Lazygit 自动检测并在文件面板中显示它们。按 Enter 打开子模块内的新 Lazygit 实例,给你对其 Git 操作的完全控制。

# Worktrees in lazygit:
#
# In Branches panel:
#   w  - create new worktree for selected branch
#        Lazygit opens a new instance in the worktree directory
#
# Equivalent git commands:
# git worktree add ../my-feature-worktree feature-branch
# git worktree list
# git worktree remove ../my-feature-worktree
#
# Submodules:
#   Automatically detected in Files panel
#   Press Enter on a submodule -> opens new lazygit instance
#   Full Git operations available within the submodule

自定义命令和键绑定

Lazygit 的 config.yml 允许你定义绑定到任意键的自定义命令。这对于项目特定的工作流非常强大,如直接从 Git 界面部署、运行测试或触发 CI 流水线。

自定义命令可以访问上下文变量,如当前分支名、选定的提交哈希和文件路径。它们可以在后台运行、在弹窗中显示输出或打开新的终端面板。

# ~/.config/lazygit/config.yml

customCommands:
  # Run tests for current project
  - key: "T"
    command: "npm test"
    context: "global"
    subprocess: true

  # Deploy current branch
  - key: "D"
    command: "git push origin \${BranchName}:deploy"
    context: "localBranches"
    loadingText: "Deploying..."
    description: "Deploy branch"

  # Create conventional commit with scope prompt
  - key: "<c-c>"
    command: >-
      git commit -m "{{.Form.Type}}({{.Form.Scope}}): {{.Form.Message}}"
    context: "files"
    prompts:
      - type: "menu"
        key: "Type"
        title: "Commit type"
        options:
          - name: "feat"
            value: "feat"
          - name: "fix"
            value: "fix"
          - name: "refactor"
            value: "refactor"
          - name: "chore"
            value: "chore"
      - type: "input"
        key: "Scope"
        title: "Scope (optional)"
      - type: "input"
        key: "Message"
        title: "Commit message"

  # Open PR for current branch on GitHub
  - key: "O"
    command: "gh pr create --web"
    context: "localBranches"
    description: "Open PR on GitHub"
    subprocess: true

  # Show commit in browser
  - key: "B"
    command: "gh browse \${CommitSha}"
    context: "commits"
    description: "Browse commit on GitHub"

Keybinding Customization

# ~/.config/lazygit/config.yml

keybinding:
  universal:
    quit: "Q"            # Change quit key
    togglePanel: "<tab>" # Default
    prevItem: "k"
    nextItem: "j"
    scrollUpMain: "<pgup>"
    scrollDownMain: "<pgdown>"
  files:
    commitChanges: "c"
    amendLastCommit: "A"
    stashChanges: "s"
  branches:
    createNewBranch: "n"
    checkoutByName: "N"
  commits:
    squashDown: "s"
    fixupCommit: "f"
    moveDownCommit: "<c-j>"
    moveUpCommit: "<c-k>"

编辑器集成:Neovim 和 VS Code

Lazygit 通过 kdheepak 的 lazygit.nvim 插件与 Neovim 无缝集成。此插件在 Neovim 内的浮动终端窗口中打开 Lazygit,绑定到可配置的键映射(通常是 <leader>gg)。当你在 Lazygit 中编辑文件时,它会在你现有的 Neovim 实例中打开。

对于 VS Code 用户,Lazygit 在集成终端中运行。你可以通过添加任务或使用终端配置文件功能来配置 VS Code 以键盘快捷键启动 Lazygit。一些用户将其绑定到 Ctrl+Shift+G 作为内置源代码管理面板的替代品。

Neovim Setup (lazygit.nvim)

-- lazy.nvim plugin spec
{
  "kdheepak/lazygit.nvim",
  cmd = {
    "LazyGit",
    "LazyGitConfig",
    "LazyGitCurrentFile",
    "LazyGitFilter",
    "LazyGitFilterCurrentFile",
  },
  dependencies = {
    "nvim-lua/plenary.nvim",
  },
  keys = {
    { "<leader>gg", "<cmd>LazyGit<cr>", desc = "Open LazyGit" },
    { "<leader>gf", "<cmd>LazyGitFilter<cr>", desc = "LazyGit filter" },
  },
}

VS Code Integration

// .vscode/tasks.json — add a task to launch lazygit
{ "version": "2.0.0", "tasks": [{
  "label": "Open Lazygit", "type": "shell", "command": "lazygit",
  "presentation": { "reveal": "always", "panel": "dedicated", "focus": true },
  "problemMatcher": []
}]}

// keybindings.json — bind to Ctrl+Shift+G
{ "key": "ctrl+shift+g", "command": "workbench.action.tasks.runTask",
  "args": "Open Lazygit" }

过滤、搜索和二分查找

在任何面板中按 / 进行过滤。在提交面板中,这让你搜索提交消息。在分支面板中,你可以按名称快速找到分支。在文件面板中,按文件名过滤。过滤是模糊的,部分匹配也能很好地工作。

Lazygit 支持 git bisect 来查找引入 bug 的提交。在提交面板中按 b 开始二分查找会话。分别用 g 和 b 标记提交为好或坏。Lazygit 将自动导航二分搜索并高亮显示罪魁祸首提交。

# Bisect workflow in lazygit:
#
# 1. Navigate to Commits panel (press 4)
# 2. Press b to start bisect
# 3. Mark the current commit as bad: b
# 4. Navigate to a known good commit: g
# 5. Lazygit checks out the midpoint automatically
# 6. Test your code, then mark as good (g) or bad (b)
# 7. Repeat until the culprit commit is found
# 8. Lazygit highlights the first bad commit
#
# Equivalent git commands:
# git bisect start
# git bisect bad HEAD
# git bisect good v1.0.0
# git bisect reset

补丁管理

Lazygit 有内置的补丁构建功能。在提交面板中,按 Enter 查看提交的差异。按空格键选择特定文件或区块添加到自定义补丁中。构建好补丁后,按 ctrl+p 打开补丁选项菜单,你可以将补丁应用到索引、从中创建新提交或复制到剪贴板。

# Patch building workflow:
#
# 1. Go to Commits panel -> Enter on a commit
# 2. Select specific files/hunks with Space
#    (adds them to the custom patch)
# 3. Press Ctrl+P to open patch options:
#    - Apply patch to index
#    - Apply patch in reverse
#    - Create new commit from patch
#    - Copy patch to clipboard
#    - Flatten patch into current index
#
# This is extremely useful for:
# - Extracting specific changes from a large commit
# - Moving changes between branches without cherry-pick
# - Creating partial reverts

主题和自定义

Lazygit 通过 config.yml 支持完整的主题定制。你可以为每个 UI 元素设置颜色,包括边框、选中行、差异高亮和面板背景。Lazygit 附带几个内置主题,也可以继承你终端的配色方案。

# ~/.config/lazygit/config.yml

# Catppuccin Mocha theme
gui:
  nerdFontsVersion: "3"
  theme:
    activeBorderColor:
      - "#a6e3a1"  # green
      - bold
    inactiveBorderColor:
      - "#585b70"  # surface2
    optionsTextColor:
      - "#89b4fa"  # blue
    selectedLineBgColor:
      - "#313244"  # surface0
    cherryPickedCommitBgColor:
      - "#45475a"  # surface1
    cherryPickedCommitFgColor:
      - "#a6e3a1"  # green
    unstagedChangesColor:
      - "#f38ba8"  # red
    defaultFgColor:
      - "#cdd6f4"  # text
    searchingActiveBorderColor:
      - "#f9e2af"  # yellow

# Other popular themes: Dracula, Gruvbox, Tokyo Night, Nord
# See: https://github.com/jesseduffield/lazygit/wiki/Custom-Themes

Additional Configuration

# ~/.config/lazygit/config.yml

gui:
  showFileTree: true          # Show files as tree instead of flat list
  showRandomTip: false        # Disable startup tips
  showCommandLog: false       # Hide command log by default
  showBottomLine: true        # Show keybinding hints at bottom
  sidePanelWidth: 0.3333      # Side panel takes 1/3 of width
  expandFocusedSidePanel: true # Auto-expand focused panel
  mainPanelSplitMode: "flexible" # flexible, horizontal, vertical
  language: "auto"            # auto, en, zh, ja, ko, etc.
  timeFormat: "02 Jan 06"     # Go time format for dates
  shortTimeFormat: "3:04PM"

git:
  paging:
    colorArg: always
    pager: delta --dark --paging=never  # Use delta for diffs
  commit:
    signOff: false
    autoWrapCommitMessage: true
    autoWrapWidth: 72
  merging:
    manualCommit: false
    args: ""                  # Extra args for git merge
  log:
    order: "topo-order"       # topo-order, date-order, author-date-order
    showGraph: "when-maximised" # always, never, when-maximised
  autoFetch: true             # Automatically fetch in background
  autoRefresh: true           # Refresh UI after Git operations

大型仓库性能

Lazygit 高效处理大型仓库,因为它将所有操作委托给 Git 而不是用 Go 重新实现 Git。对于非常大的仓库(100k+ 提交),你可以在 config.yml 中配置提交日志限制以减少内存使用。Lazygit 还支持稀疏检出和部分克隆工作流。

# Performance tuning for large repos in config.yml

git:
  log:
    showGraph: "never"         # Disable graph for faster loading
  autoFetch: false             # Disable auto-fetch on large repos
  autoRefresh: false           # Disable auto-refresh

gui:
  showFileTree: false          # Flat list is faster than tree view

# For repos with 100k+ commits:
# - Use git log --max-count to limit commit history
# - Consider git sparse-checkout for monorepos
# - Use git clone --filter=blob:none for partial clones

常见工作流

以下三个工作流展示了 Lazygit 在日常开发中的强大功能。

功能分支工作流

# Feature Branch Workflow in lazygit:
#
# 1. Create branch:    Branches panel -> n -> "feature/auth"
# 2. Make changes:     edit files in your editor
# 3. Stage changes:    Files panel -> Enter -> Space (per hunk)
# 4. Commit:           c -> "feat: add JWT authentication"
# 5. Continue work:    repeat steps 2-4
# 6. Rebase on main:   Branches panel -> select main -> r
# 7. Squash commits:   Commits panel -> s on each commit to squash
# 8. Push:             P (force push after rebase)
# 9. Create PR:        Custom command -> gh pr create --web

热修复工作流

# Hotfix Workflow in lazygit:
#
# 1. Stash current work:  Files panel -> s -> "WIP: feature work"
# 2. Checkout main:       Branches panel -> Space on main
# 3. Create hotfix:       n -> "hotfix/critical-fix"
# 4. Fix the bug:         edit files
# 5. Stage and commit:    Space -> c -> "fix: critical null check"
# 6. Push:                P
# 7. Checkout feature:    Branches panel -> Space on feature branch
# 8. Pop stash:           Stash panel -> g (pop)
# 9. Rebase on main:      Branches panel -> select main -> r

发布工作流

# Release Workflow in lazygit:
#
# 1. Checkout main:        Branches panel -> Space on main
# 2. Pull latest:          p
# 3. Create release:       n -> "release/v2.1.0"
# 4. Bump version:         edit package.json / version file
# 5. Commit:               c -> "chore: bump version to 2.1.0"
# 6. Tag:                  Commits panel -> t -> "v2.1.0"
# 7. Merge to main:        Branches panel -> select main -> M
# 8. Push with tags:       P (push), then push tags separately
#
# Push tags via custom command:
# customCommands:
#   - key: "T"
#     command: "git push --tags"
#     context: "global"

高级用户技巧

  • 在任何面板中按 ? 查看该上下文的所有可用键绑定
  • 按 + 和 - 展开和折叠侧边面板以获得更多差异空间
  • 按 x 打开操作菜单,显示当前上下文的所有可能操作
  • 使用撤销(z)和重做(ctrl+z)回退意外操作,如提交或分支删除
  • 按 @ 打开命令日志,显示 Lazygit 执行的每个 Git 命令 — 非常适合学习 Git
  • 通过在项目根目录放置 .lazygit.yml 创建特定于分支的配置
  • 按 w 打开差异菜单,并排比较任意两个引用
  • 导航到 Reflog 面板(可从提交面板选项卡访问)以恢复丢失的提交

常见问题

Lazygit 是免费开源的吗?

是的,Lazygit 完全免费,基于 MIT 许可证开源。它托管在 GitHub 的 jesseduffield/lazygit 仓库,接受社区贡献。

Lazygit 可以通过 SSH 使用吗?

可以,因为 Lazygit 是终端应用程序,它可以完美地通过 SSH 连接工作。这使得它非常适合管理远程服务器、容器和虚拟机上的 Git 仓库。

我可以在 Neovim 中使用 Lazygit 吗?

可以,kdheepak 的 lazygit.nvim 插件提供无缝的 Neovim 集成。它在浮动终端窗口中打开 Lazygit,并支持在你现有的 Neovim 会话中打开文件。

如何自定义 Lazygit 的键绑定?

编辑位于 ~/.config/lazygit/config.yml(Linux/macOS)或 %APPDATA%/lazygit/config.yml(Windows)的 config.yml 文件。keybindings 部分允许你将任何操作重新映射到任何键。

Lazygit 比 GitKraken 或 Fork 快吗?

是的,Lazygit 启动速度极快(低于 100ms),内存使用极少,因为它是没有 GUI 框架的终端应用程序。GitKraken 和 Fork 使用 Electron 或原生框架,消耗明显更多资源。

Lazygit 支持 Git LFS 吗?

是的,Lazygit 与 Git LFS 透明地配合工作。由于它将所有操作委托给 Git CLI,任何 Git 扩展(包括 LFS、Git Crypt 和 Git Annex)都会自动工作。

我可以用 Lazygit 代替命令行进行交互式变基吗?

当然可以。交互式变基是 Lazygit 最强大的功能之一。你可以通过单键快捷方式直观地重新排序、压缩、修复、编辑和删除提交,这比在文本编辑器中编辑变基待办文件要容易得多。

如何更新 Lazygit?

通过包管理器更新:macOS 上 brew upgrade lazygit,Debian/Ubuntu 上 sudo apt update && sudo apt upgrade lazygit,Windows 上 scoop update lazygit。如果通过 go install 安装,运行 go install github.com/jesseduffield/lazygit@latest。

𝕏 Twitterin LinkedIn
这篇文章有帮助吗?

保持更新

获取每周开发技巧和新工具通知。

无垃圾邮件,随时退订。

试试这些相关工具

{ }JSON Formatter

相关文章

高级Git指南:交互式变基、Reflog、Bisect、Git Hooks、子模块和Monorepo

掌握高级Git技术。涵盖Git内部原理(对象、引用、packfile)、交互式变基、reflog恢复、cherry-pick、bisect调试、合并策略、带Husky的Git hooks、子模块vs子树、工作树、GPG签名、Git LFS以及Monorepo策略。

Git 工作流指南:内部机制、分支策略、交互式变基、Hooks 与 CI/CD 集成

完整的 Git 工作流指南,涵盖内部机制、分支策略、交互式变基、cherry-pick、bisect、stash、worktree、hooks、子模块、合并与变基、reflog、提交签名、Git LFS 和 CI/CD 集成。

Vim指南:开发者完整Vim/Neovim教程

掌握Vim和Neovim。涵盖模式、导航、编辑、文本对象、宏、寄存器、分屏、标签、.vimrc配置、init.lua和telescope/coc.nvim等顶级插件的完整教程。