mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 00:58:02 +00:00
Add Resetting A Reset as a git til.
This commit is contained in:
@@ -77,6 +77,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
- [List Untracked Files](git/list-untracked-files.md)
|
- [List Untracked Files](git/list-untracked-files.md)
|
||||||
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)
|
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)
|
||||||
- [Renaming A Branch](git/renaming-a-branch.md)
|
- [Renaming A Branch](git/renaming-a-branch.md)
|
||||||
|
- [Resetting A Reset](git/resetting-a-reset.md)
|
||||||
- [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md)
|
- [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md)
|
||||||
- [Staging Changes Within Vim](git/staging-changes-within-vim.md)
|
- [Staging Changes Within Vim](git/staging-changes-within-vim.md)
|
||||||
- [Staging Stashes Interactively](git/staging-stashes-interactively.md)
|
- [Staging Stashes Interactively](git/staging-stashes-interactively.md)
|
||||||
|
|||||||
29
git/resetting-a-reset.md
Normal file
29
git/resetting-a-reset.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Resetting A Reset
|
||||||
|
|
||||||
|
Sometimes we run commands like `git reset --hard HEAD~` when we shouldn't
|
||||||
|
have. We wish we could undo what we've done, but the commit we've *reset* is
|
||||||
|
gone forever. Or is it?
|
||||||
|
|
||||||
|
When bad things happen, `git-reflog` can often lend a hand. Using
|
||||||
|
`git-reflog`, we can find our way back to were we've been; to better times.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git reflog
|
||||||
|
00f77eb HEAD@{0}: reset: moving to HEAD~
|
||||||
|
9b2fb39 HEAD@{1}: commit: Add this set of important changes
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
We can see that `HEAD@{1}` references a time and place before we destroyed
|
||||||
|
our last commit. Let's fix things by resetting to that.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ get reset HEAD@{1}
|
||||||
|
```
|
||||||
|
|
||||||
|
Our lost commit is found.
|
||||||
|
|
||||||
|
We cannot undo all the bad in the world. Any changes to tracked files will
|
||||||
|
be irreparably lost.
|
||||||
|
|
||||||
|
[source](http://stackoverflow.com/questions/2510276/undoing-git-reset)
|
||||||
Reference in New Issue
Block a user