# git reset: soft, mixed and hard on the same repository

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-reset-modes-full-en
`reset` moves the branch pointer to a target commit (default HEAD). `--soft` moves only the pointer; `--mixed` also resets the index; `--hard` also resets tracked working-tree files.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 5 tests were run, TE-05-A, TE-05-B, TE-05-C, TE-05-D and TE-05-E. The expected non-zero exit is TE-05-E (exit status 128). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-05-A: git reset --mixed restores the index to the target commit and keeps working-tree changes

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt; git add f.txt
```

Command:

```bash
git reset --mixed HEAD -- f.txt; echo EXIT=$?; echo '--cached:'; git diff --cached --name-only; echo '--worktree:'; git diff --name-only
```

Recorded output:

```
Unstaged changes after reset:
M	f.txt
EXIT=0
--cached:
--worktree:
f.txt
```

Standard error from the same run:

```
warning: --mixed with paths is deprecated; use 'git reset -- <paths>' instead.
```

This run checks the exit status and records the output; it asserts no expected text.

### TE-05-B: git reset --hard resets tracked files in the working tree and discards uncommitted edits

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt
```

Command:

```bash
git reset --hard HEAD >/dev/null; cat f.txt
```

Recorded output:

```
one
```

### TE-05-C: git reset --soft moves the branch pointer and leaves index and working tree alone

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt; git add f.txt; git commit -qm two
```

Command:

```bash
git reset --soft HEAD~1 >/dev/null; echo 'cached:'; git diff --cached --name-only; echo 'head:'; git log --oneline | wc -l
```

Recorded output:

```
cached:
f.txt
head:
1
```

### TE-05-D: the reset target need not be an earlier commit: reset can move the branch forward

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm c1
printf 'two\n' >> f.txt; git add f.txt; git commit -qm c2
printf 'three\n' >> f.txt; git add f.txt; git commit -qm c3
git rev-parse HEAD > .c3
git reset --hard HEAD~2 >/dev/null
```

Command:

```bash
git reset --soft $(cat .c3); echo move=$?; echo head=$(git log --oneline -1 --format=%s); echo staged=$(git diff --cached --name-only | tr '\n' ' ')
```

Recorded output:

```
move=0
head=c3
staged=f.txt
```

### TE-05-E: expected non-zero exit: git reset --hard with a name that is not a commit stops with a fatal error and changes nothing

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm base
printf 'edit\n' > f.txt
```

Command:

```bash
git reset --hard nosuchref; rc=$?; cat f.txt; exit $rc
```

Recorded output:

```
edit
```

Standard error from the same run:

```
fatal: ambiguous argument 'nosuchref': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
```

Exit status: 128. This status and the output match what was written before the run.

TE-05-E: git reset --hard nosuchref exited with status 128 and printed fatal: ambiguous argument 'nosuchref': unknown revision or path not in the working tree. to standard error. The cat after it printed edit, so the uncommitted edit was still in f.txt after the failed command.

## Limits

Uncommitted edits discarded by `--hard` are normally unrecoverable through Git; it is not a general untracked-file deletion tool.

## Source

- https://git-scm.com/docs/git-reset

## Evidence

- `TE-05-A`: git reset --mixed restores the index to the target commit and keeps working-tree changes
- `TE-05-B`: git reset --hard resets tracked files in the working tree and discards uncommitted edits
- `TE-05-C`: git reset --soft moves the branch pointer and leaves index and working tree alone
- `TE-05-D`: the reset target need not be an earlier commit: reset can move the branch forward

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-05-A` | git reset --mixed restores the index to the target commit and keeps working-tree changes | 0 | PASS | `0c537cd1cd69` |
| `TE-05-B` | git reset --hard resets tracked files in the working tree and discards uncommitted edits | 0 | PASS | `00099b3ae2cc` |
| `TE-05-C` | git reset --soft moves the branch pointer and leaves index and working tree alone | 0 | PASS | `f60ec3a500d5` |
| `TE-05-D` | the reset target need not be an earlier commit: reset can move the branch forward | 0 | PASS | `8865a3f1a0c2` |
| `TE-05-E` | expected non-zero exit: git reset --hard with a name that is not a commit stops with a fatal error and changes nothing | 128 | PASS | `a317cb5829cf` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [git bisect: find the commit that broke something](https://kairos-2z6s.onrender.com/res/git-bisect-full-en)
- [Git Show: read one commit](https://kairos-2z6s.onrender.com/res/git-show-full-en)
- [Git Rev Parse: ask Git for a path or a commit id](https://kairos-2z6s.onrender.com/res/git-rev-parse-full-en)
- [Git Restore: unstage or discard a file](https://kairos-2z6s.onrender.com/res/git-restore-full-en)
- [git remote: connect a repository to another one](https://kairos-2z6s.onrender.com/res/git-remote-full-en)
