Skip to content

Fix gitignore path collisions#5245

Merged
stefanhaller merged 1 commit intojesseduffield:masterfrom
DawidPietrykowski:ignore-paths
Jan 28, 2026
Merged

Fix gitignore path collisions#5245
stefanhaller merged 1 commit intojesseduffield:masterfrom
DawidPietrykowski:ignore-paths

Conversation

@DawidPietrykowski
Copy link
Copy Markdown
Contributor

PR Description

Paths added to ignore/exclude files need to be prefixed with a forward slash to point to a specific file in the directory tree.

Without that prefix a file at root called file (added to .gitignore as file) would match with ./file and ./src/file.

Example flow:

  1. User creates a directory called tests in root
  2. User sees that it's tracked
  3. User ignores the directory in Lazygit
  4. Changes in src/tests are now missing - because tests without / matches also directories lower in the tree

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller
Copy link
Copy Markdown
Collaborator

I'm a bit undecided about this. I do see the issue, but I have the feeling that in many cases (e.g. for something like .DS_Store on Mac) users do want to ignore it in every directory, so this would be a breaking change for those cases.

@DawidPietrykowski
Copy link
Copy Markdown
Contributor Author

I understand the concern, however I believe the current behavior is the more unintuitive one.

Lazygit has a file tree and when selecting what to ignore you have to pick one of the files/directories. Most users would surely expect that they'd be ignoring the selected file (be it in a subdirectory or root), but not creating a new pattern.

This could of course be extended at some point to allow you to select ignore everywhere in tree or something like that.

Another point is that it's safer to be explicit, current behavior can lead to accidentally uncommited changes. The one I'm trying to introduce leads to minor inconvenience at most (having to add a line manually to .gitignore).

@stefanhaller stefanhaller added the enhancement New feature or request label Jan 28, 2026
@stefanhaller
Copy link
Copy Markdown
Collaborator

Ok, fair enough. We will probably extend the current gitignore command at some point to show a menu with options to ignore this exact file, or all files with the same extension, or to edit the file, and at that point we can consider if we want to add with/without leading slash options too (but maybe rather not).

I added a fixup (5b63c0a) for a minor fix to the comment.

Paths added to ignore/exclude files need to be prefixed with a forward
slash to point to a specific file in the directory tree.

Without that prefix a file at root called `file` (added to `.gitignore`
as `file`) would match with `./file` and `./src/file`.
@stefanhaller stefanhaller merged commit 819212b into jesseduffield:master Jan 28, 2026
13 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 15, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.58.1` → `v0.59.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.59.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.59.0)

[Compare Source](jesseduffield/lazygit@v0.58.1...v0.59.0)

<!-- Release notes generated using configuration in .github/release.yml at v0.59.0 -->

#### What's Changed

##### Enhancements 🔥

- Have "Find base commit for fixup" ignore fixup commits for the found base commit by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5210](jesseduffield/lazygit#5210)
- Exclude commit trailers from line wrapping by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5230](jesseduffield/lazygit#5230)
- Limit popup panel widths to a maximum width by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5231](jesseduffield/lazygit#5231)
- Support using the selected commit's message in a fixup by [@&#8203;jesseduffield](https://github.com/jesseduffield) in [#&#8203;5233](jesseduffield/lazygit#5233)
- Fix gitignore path collisions by [@&#8203;DawidPietrykowski](https://github.com/DawidPietrykowski) in [#&#8203;5245](jesseduffield/lazygit#5245)

##### Fixes 🔧

- Don't log the "git rev-list" call when marking bisect commits by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5236](jesseduffield/lazygit#5236)
- Fix opening a menu when a previous menu was scrolled down by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5238](jesseduffield/lazygit#5238)
- When moving commits up/down and the selection leaves the view, scroll to make it visible again by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5247](jesseduffield/lazygit#5247)
- Fix rendering of CRLF sequence ('\r\n') by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5237](jesseduffield/lazygit#5237)
- Fix rendering of the Reflog panel when using up/down to scroll it by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5248](jesseduffield/lazygit#5248)
- Add Nushell support for nvim-remote preset by [@&#8203;baiyeidk](https://github.com/baiyeidk) in [#&#8203;5250](jesseduffield/lazygit#5250)

##### Maintenance ⚙️

- Update devcontainer `VARIANT` to `1-trixie` by [@&#8203;mricherzhagen](https://github.com/mricherzhagen) in [#&#8203;5204](jesseduffield/lazygit#5204)
- chore: Update outdated GitHub Actions versions by [@&#8203;pgoslatara](https://github.com/pgoslatara) in [#&#8203;5220](jesseduffield/lazygit#5220)
- Disable the automatic, scheduled release by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5272](jesseduffield/lazygit#5272)
- Auto-update cheatsheets after updating translation by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5275](jesseduffield/lazygit#5275)

##### Docs 📖

- Update README to add GitArbor TUI as an alternative by [@&#8203;cadamsdev](https://github.com/cadamsdev) in [#&#8203;5257](jesseduffield/lazygit#5257)
- Update docs and schema for release by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5276](jesseduffield/lazygit#5276)

##### I18n 🌎

- Update translations from Crowdin by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5274](jesseduffield/lazygit#5274)

#### New Contributors

- [@&#8203;pgoslatara](https://github.com/pgoslatara) made their first contribution in [#&#8203;5220](jesseduffield/lazygit#5220)
- [@&#8203;cadamsdev](https://github.com/cadamsdev) made their first contribution in [#&#8203;5257](jesseduffield/lazygit#5257)
- [@&#8203;baiyeidk](https://github.com/baiyeidk) made their first contribution in [#&#8203;5250](jesseduffield/lazygit#5250)

**Full Changelog**: <jesseduffield/lazygit@v0.58.1...v0.59.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Ni4yIiwidXBkYXRlZEluVmVyIjoiNDIuOTYuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants