jesseduffield/lazygit

GitHub: jesseduffield/lazygit

一个用 Go 编写的 Git 终端 UI 工具,通过可视化界面和快捷键简化复杂的 Git 操作。

Stars: 73307 | Forks: 2550

Special thanks to:

Warp
Warp, the intelligent terminal
Available for MacOS and Linux
Visit warp.dev to learn more.


Tuple
Tuple, the premier screen sharing app for developers on macOS and Windows.



Subble
I (Jesse) co-founded Subble to save your company time and money by finding unused and over-provisioned SaaS licences. Check it out!


一个用于 git 命令的简单终端 UI
[![GitHub Releases](https://img.shields.io/github/downloads/jesseduffield/lazygit/total)](https://github.com/jesseduffield/lazygit/releases) [![Go Report Card](https://goreportcard.com/badge/github.com/jesseduffield/lazygit)](https://goreportcard.com/report/github.com/jesseduffield/lazygit) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f46416b715d74622895657935fcada21)](https://app.codacy.com/gh/jesseduffield/lazygit/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f46416b715d74622895657935fcada21)](https://app.codacy.com/gh/jesseduffield/lazygit/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage) [![golangci-lint](https://img.shields.io/badge/linted%20by-golangci--lint-brightgreen)](https://golangci-lint.run/) [![GitHub tag](https://img.shields.io/github/v/tag/jesseduffield/lazygit?color=blue)](https://github.com/jesseduffield/lazygit/releases/latest) [![homebrew](https://img.shields.io/homebrew/v/lazygit?color=blue)](https://formulae.brew.sh/formula/lazygit) ![commit_and_push](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/1649c860b7172342.gif)
## 电梯演讲 吐槽时间:你可能听过这种说法,git 很_强大_,但如果所有操作都难得要死,这强大又有何用?交互式变基竟然要你在编辑器里编辑一个该死的 TODO 文件?_你在开玩笑吗?_ 想要暂存文件的一部分,你需要用命令行程序逐个检查每个 hunk,如果一个 hunk 无法再拆分但包含你不想暂存的代码,你必须_手动_编辑一个晦涩的补丁文件?_你在逗我吗?!_ 有时切换分支会被要求暂存更改,结果切换并恢复暂存后发现根本没冲突,直接 checkout 那个分支也完全没问题?_这简直不可理喻!_ 如果你像我一样只是个普通凡人,听腻了 git 有多强大,但在日常使用中却觉得它是个大麻烦,那么 lazygit 可能适合你。 ## 目录 ## 功能 ### 暂存单行 在选中的行上按空格键以暂存它,或按 `v` 开始选择多行范围。你也可以按 `a` 来选择当前 hunk 的全部内容。 ![stage_lines](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/bd7789cc78172344.gif) ### 交互式变基 按 `i` 启动交互式变基。然后可以对 TODO commits 进行 squash (`s`)、fixup (`f`)、drop (`d`)、edit (`e`)、上移 (`ctrl+k`) 或下移 (`ctrl+j`),之后通过 `m` 调出变基选项菜单并选择 `continue` 以继续变基。 你也可以一次性执行这些操作(例如在某个 commit 上按 `s` 进行 squash),而无需显式启动变基。 此演示还使用了 shift+down 来选择一组 commit 进行移动和 fixup。 ![interactive_rebase](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/2ce92b3f08172347.gif) ### Cherry-pick 在某个 commit 上按 `shift+c` 复制它,然后按 `shift+v` 粘贴(cherry-pick)它。 ![cherry_pick](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/a843a89732172350.gif) ### Bisect 在 commits 视图中按 `b` 将 commit 标记为 good/bad 以开始 git bisect。 ![bisect](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/097e48461c172353.gif) ### 清空工作区 当你真的想清除运行 `git status` 时显示的所有内容(是的,包括脏的 submodules)时,就像 [kidpix 风格](https://www.youtube.com/watch?v=N4E2B_k2Bss)那样,按 `shift+d` 调出重置选项菜单,然后选择 'nuke' 选项。 ![Nuke working tree](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/7b7a2cbd78172357.gif) ### 修改旧的 commit 在任意 commit 上按 `shift+a` 将使用当前已暂存的更改修改该 commit(在后台运行交互式变基)。 ![amend_old_commit](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0c7cea4668172400.gif) ### 过滤 你可以使用 `/` 过滤视图。在这里我们过滤分支视图,然后按 `enter` 查看其 commits。 ![filter](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/fa652eb16d172402.gif) ### 调用自定义命令 Lazygit 拥有一个非常灵活的 [自定义命令系统](docs/Custom_Command_Keybindings.md)。在这个例子中,定义了一个模拟内置分支 checkout 操作的自定义命令。 ![custom_command](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/3bbdd59dfa172405.gif) ### Worktrees 你可以创建 worktrees 以同时处理多个分支,无需在切换时 stash 或创建 WIP commits。在 branches 视图中按 `w` 从选中的分支创建一个 worktree 并切换到它。 ![worktree_create_from_branches](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/5248b708b5172408.gif) ### 变基魔法(自定义补丁) 你可以从旧的 commit 构建自定义补丁,然后从 commit 中移除该补丁、拆分出新的 commit、将补丁反向应用到 index 等等。 在这个例子中,我们有一个冗余的注释想要从旧的 commit 中移除。我们在 commit 上按 `` 查看其文件,然后在文件上按 `` 聚焦补丁,接着按 `` 将注释行添加到我们的自定义补丁中,最后按 `ctrl+p` 查看自定义补丁选项;选择从当前 commit 中移除补丁。 在 [Rebase magic Youtube 教程](https://youtu.be/4XaToVut_hs)中了解更多。 ![custom_patch](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/3f2ae366c6172412.gif) ### 从标记的基础 commit 变基 假设你在一个 feature 分支上,该分支是从 develop 分支分出来的,而你决定改为从 master 分支分出来。你需要一种方法仅变基 feature 分支上的 commits。在这个演示中,我们检查 develop 分支上的最后一个 commit 是哪个,然后按 `shift+b` 将该 commit 标记为我们的基础 commit,接着在 master 分支上按 `r` 变基到它,只带入 feature 分支的 commits。然后用 `shift+p` 推送我们的更改。 ![rebase_onto](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/d78801fee3172416.gif) ### 撤销 你可以通过按 `z` 撤销上一步操作,用 `ctrl+z` 重做。这里我们丢弃了几个 commits,然后撤销了这些操作。 撤销使用的是 reflog,它仅针对 commits 和 branches,所以我们无法撤销工作区或 stash 的更改。 [更多信息](/docs/Undoing.md) ![undo](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/97d78e8f66172418.gif) ### Commit 图 在放大的窗口中查看 commit 图时(使用 `+` 和 `_` 切换屏幕模式),会显示 commit 图。颜色对应 commit 作者,当你在图中向下导航时,选中 commit 的父 commits 会被高亮显示。 ![commit_graph](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0657db4c0d172421.gif) ### 比较两个 commits 如果你在某个 commit(或 branch/ref)上按 `shift+w`,会打开一个菜单允许你标记该 commit,这样你选择的任何其他 commit 都会与它进行 diff。选择第二个 commit 后,你会在主视图中看到 diff,如果按 ``,你会看到 diff 的文件。你可以再次按 `shift+w` 查看 diff 菜单,选择反转 diff 方向或退出 diff 模式等选项。你也可以按 `` 退出 diff 模式。 ![diff_commits](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0beb4e5e5d172423.gif) ## 教程 [](https://youtu.be/CPLdltN7wgE) - [15 分钟掌握 15 个 Lazygit 功能](https://youtu.be/CPLdltN7wgE) - [基础教程](https://youtu.be/VDXvbHZYeKY) - [变基魔法教程](https://youtu.be/4XaToVut_hs) ## 安装 [![Packaging status](https://repology.org/badge/vertical-allrepos/lazygit.svg?columns=3)](https://repology.org/project/lazygit/versions) _上述大部分包由第三方维护,因此请务必自行审查,确认维护者看起来是个值得信赖的人,比如参加当地体育比赛并通过烧烤筹款回馈社区等_ ### 二进制发布版 对于 Windows、Mac OS(10.12+) 或 Linux,你可以在这里下载二进制发布版[这里](../../releases)。 ### Dev container 功能 如果你想在例如你的 GitHub Codespaces 中使用 lazygit,有一个基于上述二进制发布版的第三方 [dev container 功能](https://github.com/GeorgOfenbeck/features/tree/main/src/lazygit-linuxbinary)。 ### Homebrew 它也适用于 Linux。 ``` brew install lazygit ``` ### MacPorts 从 github releases 构建的最新版本。 Tap: ``` sudo port install lazygit ``` ### Void Linux Void Linux 的包可在 distro repo 中找到 它们跟随上游最新版本 ``` sudo xbps-install -S lazygit ``` ### Scoop (Windows) 你可以使用 [scoop](https://scoop.sh/) 安装 `lazygit`。它在 `extras` bucket 中: ``` # 添加 extras bucket scoop bucket add extras # 安装 lazygit scoop install lazygit ``` ### gah (Linux 和 Mac OS) 你可以使用 [gah](https://github.com/marverix/gah/) 安装 `lazygit`: ``` gah install lazygit ``` ### Arch Linux Arch Linux 的包可通过 pacman 和 AUR (Arch User Repository) 获得。 有两个包。稳定版使用最新 release 构建 git 版本使用最近的 commit 构建。 - Stable: `sudo pacman -S lazygit` - Development: 安装 AUR 内容的说明可以在这里找到: ### Fedora / Amazon Linux 2023 / CentOS Stream Fedora、Amazon Linux 2023 和 CentOS Stream 的包可通过 [Copr](https://copr.fedorainfracloud.org/coprs/dejan/lazygit/) (Cool Other Package Repo) 获得。 ``` sudo dnf copr enable dejan/lazygit sudo dnf install lazygit ``` 这些包使用位于此处的 RPM spec 文件构建:https://codeberg.org/dejan/rpm-lazygit 你应该能够为 Fedora 41 或更早版本以及其他 Fedora 衍生版构建 RPM,使用 你可以从最新 COPR 构建中获取的 SRPM (Source RPM) 文件。 #### Fedora / RHEL 衍生版 Fedora 和 RHEL 衍生版的包也可以从 [Terra Repository](https://terra.fyralabs.com/) 获得。 ``` sudo dnf install --nogpgcheck --repofrompath 'terra,https://repos.fyralabs.com/terra$releasever' terra-release sudo dnf install lazygit ``` (Atomic/EL 的安装指南可以在他们的 [README](https://github.com/terrapkg/packages/pull/9747) 中找到) Terra 还有 `lazygit-doc`,其中包含 [docs](https://github.com/jesseduffield/lazygit/tree/master/docs) 文件夹的内容。 ### Solus Linux ``` sudo eopkg install lazygit ``` ### Debian 和 Ubuntu 对于 **Debian 13 "Trixie", Sid** 及更高版本,或 **Ubuntu 25.10 "Questing Quokka"** 及更高版本: ``` sudo apt install lazygit ``` 对于 **Debian 12 "Bookworm", Ubuntu 25.04 "Plucky Puffin"** 及更早版本: ``` 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/download/v${LAZYGIT_VERSION}/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" tar xf lazygit.tar.gz lazygit sudo install lazygit -D -t /usr/local/bin/ ``` 验证 lazygit 是否正确安装: ``` lazygit --version ``` ### Funtoo Linux Funtoo Linux 在 [dev-kit](https://github.com/funtoo/dev-kit/tree/1.4-release/dev-vcs/lazygit) 中有一个自动生成的 lazygit 包: ``` sudo emerge dev-vcs/lazygit ``` ### Gentoo Linux Lazygit(尚)不在 Gentoo portage 主库中,但在 [GURU overlay](https://github.com/gentoo-mirror/guru/tree/master/dev-vcs/lazygit) 中有 ebuild 可用 你可以将 overlay 添加到你的系统并像往常一样安装 lazygit: ``` sudo eselect repository enable guru sudo emaint sync -r guru sudo emerge dev-vcs/lazygit ``` ### openSUSE lazygit 包目前在 [devel:languages:go/lazygit](https://build.opensuse.org/package/show/devel:languages:go/lazygit) 中构建。 要在 openSUSE Tumbleweed 上安装 lazygit,运行: ``` sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/go/openSUSE_Factory/devel:languages:go.repo sudo zypper ref && sudo zypper in lazygit ``` 要在 openSUSE Leap 上安装 lazygit,运行: ``` source /etc/os-release sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/go/$VERSION_ID/devel:languages:go.repo sudo zypper ref && sudo zypper in lazygit ``` ### NixOS #### 使用 nixpkgs 中的 lazygit 在 NixOS 上,lazygit 由 nix 打包并通过 nixpkgs 分发。 你可以在不安装的情况下试用 lazygit: ``` nix-shell -p lazygit # 或启用 flakes nix run nixpkgs#lazygit ``` 或者你可以使用 `environment.systemPackages` 选项将 lazygit 添加到你的 `configuration.nix` 中。 更多详情可通过 NixOS 搜索[页面](https://search.nixos.org/)找到。 #### 使用官方 lazygit flake 此仓库包含一个 nix flake,提供最新的开发版本和额外的开发工具: **直接从仓库运行 lazygit:** ``` nix run github:jesseduffield/lazygit # 或从本地 clone nix run . ``` **从源码构建 lazygit:** ``` nix build github:jesseduffield/lazygit # 或从本地 clone nix build . ``` **开发环境:** 对于贡献者,flake 提供了一个带有 Go 工具链、开发工具和依赖项的开发 shell: ``` nix develop github:jesseduffield/lazygit # 或从本地 clone nix develop ``` 开发 shell 包括: - Go 工具链 - git 和 make - 适当的开发环境变量 **在其他 flakes 中使用:** flake 还提供了一个 overlay,便于集成到其他基于 flake 的项目中: ``` { inputs.lazygit.url = "github:jesseduffield/lazygit"; outputs = { self, nixpkgs, lazygit }: { # Use the overlay nixpkgs.overlays = [ lazygit.overlays.default ]; }; } ``` ### Flox Lazygit 可以按如下方式安装到 Flox 环境中。 ``` flox install lazygit ``` 关于 Flox 的更多详情可以在[他们的网站](https://flox.dev/)上找到。 ### FreeBSD ``` pkg install lazygit ``` ### Termux ``` apt install lazygit ``` ### Conda 不同平台有已发布的版本,请参阅 ``` conda install -c conda-forge lazygit ``` ### Go ``` go install github.com/jesseduffield/lazygit@latest ``` 请注意: 如果你收到声称找不到 lazygit 或未定义的错误,你 可能需要将 `~/go/bin` 添加到你的 $PATH (MacOS/Linux),或 `%HOME%\go\bin` (Windows)。不要与 `C:\Go\bin 混淆(那是 Go 自己的二进制文件, 而不是像 lazygit 这样的应用程序)。 ### Chocolatey (Windows) 你可以使用 [Chocolatey](https://chocolatey.org/) 安装 `lazygit`: ``` choco install lazygit ``` ### Winget (Windows 10 1709 或更高版本) 你可以使用 Windows 终端中的 `winget` 命令通过以下命令安装 `lazygit`: ``` winget install -e --id=JesseDuffield.lazygit ``` ### 手动安装 你需要[安装 Go](https://golang.org/doc/install) ``` git clone https://github.com/jesseduffield/lazygit.git cd lazygit go install ``` 你也可以使用 `go run main.go` 一步完成编译和运行(绝对是有意双关) ## 用法 在 git 仓库内的终端中调用 `lazygit`。 ``` $ lazygit ``` 如果你愿意,你 也可以使用 `echo "alias lg='lazygit'" >> ~/.zshrc` 添加别名(或 任何你正在使用的 rc 文件)。 ### 快捷键绑定 你可以查看快捷键绑定列表[这里](/docs/keybindings)。 ### 退出时更改目录 如果你在 lazygit 中切换了仓库,并希望 shell 在退出 lazygit 时切换到该仓库的目录,请将此添加到你的 `~/.zshrc`(或其他 rc 文件): ``` lg() { export LAZYGIT_NEW_DIR_FILE=~/.lazygit/newdir lazygit "$@" if [ -f $LAZYGIT_NEW_DIR_FILE ]; then cd "$(cat $LAZYGIT_NEW_DIR_FILE)" rm -f $LAZYGIT_NEW_DIR_FILE > /dev/null fi } ``` 然后 `source ~/.zshrc`,从现在开始当你调用 `lg` 并退出时,你会切换到你在 lazygit 中所在的目录。要覆盖此行为,你可以使用 `shift+Q` 而不是 `q` 退出。 ### 撤销/重做 请参阅[文档](/docs/Undoing.md) ## 配置 请查看[配置文档](docs/Config.md)。 ### 自定义分页器 请参阅[文档](docs/Custom_Pagers.md) ### 自定义命令 如果 lazygit 缺少某个功能,很有可能你可以通过自定义命令自己实现它! 请参阅[文档](docs/Custom_Command_Keybindings.md) ### Git flow 支持 如果你安装了 [Gitflow](https://github.com/nvie/gitflow),Lazygit 支持 Gitflow。要了解 Gitflow 模型的工作原理,请查看 Vincent Driessen 解释它的原始[文章](https://nvie.com/posts/a-successful-git-branching-model/)。要在 Lazygit 中查看 Gitflow 选项,请在 branches 视图中按 `i`。 ## 贡献 我们欢迎你的投入!请查看[贡献指南](CONTRIBUTING.md)。 对于不适合在 repo 中讨论的贡献者话题,请加入 [discord channel](https://discord.gg/ehwFt2t4wt) 如果你想了解从哪里开始,请查看这个[视频](https://www.youtube.com/watch?v=kNavnhzZHtk),它演示了如何在 lazygit 中创建一个小功能。 ### 本地调试 在一个终端标签页运行 `lazygit --debug`,在另一个终端运行 `lazygit --logs` 以并排查看程序及其日志输出 ## 捐赠 如果你想支持 lazygit 的开发,请考虑[赞助我](https://github.com/sponsors/jesseduffield)(github 正在进行所有捐款 12 个月内一比一配对) ## 常见问题 ### commit 颜色代表什么? - 绿色:该 commit 包含在 master 分支中 - 黄色:该 commit 不包含在 master 分支中 - 红色:该 commit 尚未推送到上游分支 ## 自我推销 如果你想看我 在开发方面在做什么,请在 [twitter](https://twitter.com/DuffieldJesse) 上关注我或查看我的[博客](https://jesseduffield.com/) ## 替代品 如果你发现 lazygit 不能完全满足你的要求,这些可能更适合: - [GitUI](https://github.com/Extrawurst/gitui) - [tig](https://github.com/jonas/tig) - [GitArbor TUI](https://github.com/cadamsdev/gitarbor-tui)
标签:EVTX分析, EVTX分析, Git, Go, GUI, MacOS, Ruby工具, TUI, 威胁情报, 安全可观测性, 开发者工具, 开源, 效率工具, 日志审计, 源代码管理, 版本控制, 终端用户界面