# Implement staging and unstaging hunks \(\#24606\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/eea6b526dcdd49cf70abdfaa9efaf99be531f99e)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: eea6b526dcdd49cf70abdfaa9efaf99be531f99e

Requested commit: eea6b526dcdd49cf70abdfaa9efaf99be531f99e

Commit: eea6b526dcdd49cf70abdfaa9efaf99be531f99e

Tree: b752b8ed6e753e72fd7eb06f4e87934f9514c0a4

Author: Cole Miller

Committer: GitHub

## Message

```
Implement staging and unstaging hunks (#24606)

- [x] Staging hunks
- [x] Unstaging hunks
- [x] Write a randomized test
- [x] Get test passing
- [x] Fix existing bug in diff_base_byte_range computation
- [x] Remote project support
- [ ] ~~Improve performance of
buffer_range_to_unchanged_diff_base_range~~
- [ ] ~~Bug: project diff editor scrolls to top when staging/unstaging
hunk~~ existing issue
- [ ] ~~UI~~ deferred
- [x] Tricky cases
  - [x] Correctly handle acting on multiple hunks for a single file
- [x] Remove path from index when unstaging the last staged hunk, if
it's absent from HEAD, or staging the only hunk, if it's deleted in the
working copy

Release Notes:

- Add `ToggleStagedSelectedDiffHunks` action for staging and unstaging
individual diff hunks
```

## Parents

- [ea8da43c6bb620d78bf0d96dec65d76f4492dd1b](https://git.cafe/gitcafe/zed/commit/ea8da43c6bb620d78bf0d96dec65d76f4492dd1b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/eea6b526dcdd49cf70abdfaa9efaf99be531f99e?format=markdown)
