Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change reset to restore --staged and add an example #90

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 62 additions & 5 deletions episodes/06-reverting-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,68 @@ Generally it is best to spot and revert mistakes before the commit stage.
The table below summarises how to revert a change depending on where in the
commit process you are:

| **To revert files you have ...** | **git command** |
|:--------------------------------:|:-----------------------:|
| modified | `$ git restore <files>` |
| staged | `$ git reset <files>` |
| committed | `$ git revert <commit>` |
| **To revert files you have ...** | **git command** |
|:--------------------------------:|:--------------------------------:|
| modified | `$ git restore <files>` |
| staged | `$ git restore --staged <files>` |
| committed | `$ git revert <commit>` |

We have already practised restoring modified files.
Now let's practise restoring staged changes.
Go ahead and make a similar change like you did earlier
to your `forecast.md`:

```bash
$ nano forecast.md
$ cat forecast.md
```

```output
# Forecast

## Today

Cloudy with a chance of sun.
Mild temperatures around 16 °C.

## Tomorrow

Morning rainbows followed by light showers.
Another ill-considered change.
```

Add the changes:

```bash
$ git add forecast.md
```

Now `git status` shows:

```bash
$ git status
```

```output
On branch forecast
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: forecast.md
```

And we can use the hint to unstage our changes:

```bash
$ git restore --staged forecast.md
```

Our modifications to the `forecast.md` file have been unstaged
and are now back in the working copy.
We can restore these modifications fully with:

```bash
$ git restore forecast.md
```

::::::::::::::::::::::::::::::::::::::: challenge

Expand Down