aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2025-02-20 20:41:51 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2025-02-20 20:41:51 +0100
commitf6e78d5746b77bb48cdfee50b73da0dc26e3bcb9 (patch)
tree192f79c83fec0ae50ca0ee7ebf562b9c4e6bd71d
parent496a4126f52649ea954ce6be2cdfeb1d7a02c372 (diff)
downloadnotes-f6e78d5746b77bb48cdfee50b73da0dc26e3bcb9.tar.gz
notes-f6e78d5746b77bb48cdfee50b73da0dc26e3bcb9.zip
git: example for soft/mixed/hard reset
-rw-r--r--src/development/git.md44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/development/git.md b/src/development/git.md
index 55748f4..7b5dde1 100644
--- a/src/development/git.md
+++ b/src/development/git.md
@@ -4,13 +4,15 @@
```text
+-------------------+ --- stash -----> +-------+
| working directory | | stash | // Shelving area.
-+-------------------+ <-- stash pop -- +-------+
+| (worktree) | <-- stash pop -- +-------+
++-------------------+
| ^
add |
| reset
v |
+-------------------+
| staging area |
+| (index) |
+-------------------+
|
commit
@@ -195,8 +197,44 @@ the same repository (shared .git folder).
tracked files in the working tree since
<commit> are lost
git reset HEAD <file> .......... remove file from staging
- git reset --soft HEAD~1 ........ delete most recent commit but keep work
- git reset --hard HEAD~1 ........ delete most recent commit and delete work
+ git reset --soft HEAD~1 ........ delete most recent commit; dont revert index & worktree
+ git reset --mixed HEAD~1 ....... delete most recent commit; revert index; dont revert worktree
+ git reset --hard HEAD~1 ........ delete most recent commit; revert index & worktree
+```
+
+Assuming an initial history `A - B - C - D` where `HEAD` currently points at
+`D`, the different reset operations work as shown below.
+
+**Soft** reset.
+```
+git reset --soft HEAD~2
+
+history: A - B
+ ^HEAD
+
+-> local history is reverted, HEAD moved to B.
+-> changes from C + D are still in the worktree & index (appear as staged changes).
+```
+**Mixed** reset.
+```
+git reset --mixed HEAD~2
+
+history: A - B
+ ^HEAD
+
+-> local history is reverted, HEAD moved to B.
+-> changed from C + D are reverted in the index.
+-> changes from C + D are still in the worktree (appear as unstaged changes).
+```
+**Hard** reset.
+```
+git reset --head HEAD~2
+
+history: A - B
+ ^HEAD
+
+-> local history is reverted, HEAD moved to B.
+-> changes from C + D also reverted in the worktree & index (no pending changes).
```
## Submodules