Add rewind snippets

This commit is contained in:
Isabelle Viktoria Maciohsek
2021-04-05 11:19:21 +03:00
parent aa8ddd1312
commit 50b79bde68
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
title: Rewind back n commits
tags: branch,commit,intermediate
---
Rewinds the current branch by a given number of commits.
- Use `git reset HEAD~<n>` to rewind the current branch `<n>` commits.
- This command will uncommit and unstage changes, but leave them in the working directory.
- You can use the `--hard` flag to uncommit, unstage and delete changes instead.
```sh
git reset [--hard] HEAD~<n>
```
```sh
git reset HEAD~5
# Rewinds back 5 commits but keeps changes in the working directory
git reset --hard HEAD~3
# Rewinds back 3 commits and deletes changes
```

View File

@ -0,0 +1,22 @@
---
title: Rewind back to a specific commit
tags: branch,commit,intermediate
---
Rewinds the current branch by a given number of commits.
- Use `git reset <commit>` to rewind the current branch to the specified `<commit>`.
- This command will uncommit and unstage changes, but leave them in the working directory.
- You can use the `--hard` flag to uncommit, unstage and delete changes instead.
```sh
git reset [--hard] <commit>
```
```sh
git reset --hard 3050fc0d3
# Rewinds back to `3050fc0d3` but keeps changes in the working directory
git reset --hard c0d30f305
# Rewinds back to `c0d30f305` and deletes changes
```