# Git hard reset

### Tasks

1. Navigate to `/usr/src/kodekloudrepos/demo` git repository on the Storage server.
2. Reset the repository so that only two commits remain:
   * `initial commit`
   * `add data.txt file`
3. Make sure the working directory and HEAD are aligned to `add data.txt file`.
4. Push the updated state to the remote, replacing existing history.

### Steps

{% stepper %}
{% step %}
SSH to storage server and switch to root if needed

```bash
ssh natasha@ststor01
sudo su -
```

{% endstep %}

{% step %}

### Navigate to demo directory

```
cd /usr/src/kodekloudrepos/demo
```

{% endstep %}

{% step %}
Find the commit hash for "add data.txt file"

```
git log --oneline
```

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2F3R2UEUh7ntITn6AmjP8w%2Fimage.png?alt=media&#x26;token=595c836b-a76a-4291-8bed-6bd5e6664f69" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Reset to "add data.txt file"

```
git rebase -i --root
```

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2FkxIO4OAPD3JBG2wFe0zk%2Fimage.png?alt=media&#x26;token=685be979-1bb4-4434-8190-fcd7f7eaae41" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Keep only:

* `initial commit`
* `add data.txt file`

(Delete or drop other commits in the interactive editor)

```
git rebase -i --root
```

{% endstep %}

{% step %}
Force push cleaned-up history

```
git push origin master --force
```

{% endstep %}

{% step %}
Verify only two commits remain

```
git log --oneline
```

<figure><img src="https://3155059101-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ftpxp8dhlubc3j58Iygn5%2Fuploads%2Fa22ObRCNS8shLs2ZrkwE%2Fimage.png?alt=media&#x26;token=d7f17faa-38cb-45be-8889-e82dc33878c1" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}
