diff --git a/snippets/rewind-n-commits.md b/snippets/rewind-n-commits.md new file mode 100644 index 000000000..7dcff6683 --- /dev/null +++ b/snippets/rewind-n-commits.md @@ -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~` to rewind the current branch `` 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~ +``` + +```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 +``` diff --git a/snippets/rewind-to-commit.md b/snippets/rewind-to-commit.md new file mode 100644 index 000000000..e8cb58d00 --- /dev/null +++ b/snippets/rewind-to-commit.md @@ -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 ` to rewind the current branch to the specified ``. +- 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] +``` + +```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 +```