Files
30-seconds-of-code/snippets/rewind-n-commits.md
Isabelle Viktoria Maciohsek ed2f41b0d8 Bake dates into snippets
2021-06-13 19:47:48 +03:00

659 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
Rewind back n commits branch,commit,intermediate 2021-04-05T11:19:21+03:00 2021-04-13T21:10:59+03:00

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.
git reset [--hard] HEAD~<n>
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