github-desktop/docs/technical/discard-changes.md

42 lines
1.6 KiB
Markdown
Raw Normal View History

2018-06-10 11:39:58 +00:00
# Discard Changes
The `Discard Changes` feature allows users to clean up uncommitted changes from
a repository, and has evolved over time to support different workflows.
## Implementation
As the implementation details of this may change over time, this section will
2018-06-10 22:32:37 +00:00
instead describe the high-level flow of the implementation.
2018-06-10 11:39:58 +00:00
You can view a reference of this function [here](https://github.com/desktop/desktop/blob/2b111155914cb44824b39ee197deed23bb825a1a/app/src/lib/stores/git-store.ts#L1066).
The `Discard Changes` flow is composed of multiple steps.
### Moving Files to Trash
2021-07-22 10:56:39 +00:00
Electron provides the [`shell.trashItem(fullPath)`](https://www.electronjs.org/docs/api/shell#shelltrashitempath)
2018-06-10 11:39:58 +00:00
API to manage moving files into the OS-specific trash.
Desktop uses this API to move _all new or modified files_ out from the
repository as a way to preserve changes, in case the user wishes to recover
them later. Files moved to the Trash are moved over as-is, so ensure you have
the ability to view hidden files if you wish to recover files that are prefixed
with `.`.
### Reset Paths
The next step is identifying any files that have been listed for discard that
are also staged in the index. While Desktop doesn't stage files itself, a user
2018-06-10 22:32:37 +00:00
might be using other tools alongside Desktop, so this is a sanity check before
proceeding to the next stage.
2018-06-10 11:39:58 +00:00
2018-06-10 22:32:37 +00:00
**Git CLI equivalent**: `git reset HEAD -- [path]`
2018-06-10 11:39:58 +00:00
### Checkout Paths
The last step is to replace the modified files in the working directory with
whatever is currently in the index - this ensures that Desktop only replaces
files that the user has chosen to discard.
2018-06-10 22:32:37 +00:00
**Git CLI equivalent**: `git checkout-index -f -u -- [path]`