Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| git_undoing_things [2019/02/26 12:04] – [Throwing away all staged and unstaged changes] rpjday | git_undoing_things [2019/02/26 12:32] (current) – [Unstaging staged content] rpjday | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Overview ===== | ===== Overview ===== | ||
| - | Various ways to undo, backpedal and regret. | + | Various ways to undo, backpedal and regret |
| ===== The state of files ===== | ===== The state of files ===== | ||
| Line 27: | Line 27: | ||
| ==== Undoing unstaged changes (part one) ==== | ==== Undoing unstaged changes (part one) ==== | ||
| - | From '' | + | Say you've made some local changes, but have staged nothing so far. From '' |
| < | < | ||
| Line 44: | Line 44: | ||
| </ | </ | ||
| - | To undo //all// unstaged changes: | + | To undo //all// unstaged changes |
| < | < | ||
| Line 52: | Line 52: | ||
| ==== Undoing unstaged changes (part deux) ==== | ==== Undoing unstaged changes (part deux) ==== | ||
| - | If you have already staged some changes, made additional changes and want to undo just those local (unstaged) changes, see above. | + | If you have already staged some changes, |
| < | < | ||
| Line 79: | Line 79: | ||
| </ | </ | ||
| - | End result: | + | End result |
| < | < | ||
| Line 110: | Line 110: | ||
| </ | </ | ||
| - | Recall how to do this for everything: | + | Recall how to do this for everything |
| < | < | ||
| $ git reset --hard | $ git reset --hard | ||
| + | </ | ||
| + | |||
| + | ==== Unstaging staged content ==== | ||
| + | |||
| + | From '' | ||
| + | |||
| + | < | ||
| + | git reset [< | ||
| + | |||
| + | ... | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | and reports what has not been updated. This is the | ||
| + | | ||
| + | </ | ||
| + | |||
| + | Example: | ||
| + | |||
| + | < | ||
| + | $ git reset -- README | ||
| + | </ | ||
| + | |||
| + | ==== Restoring accidentally-deleted files ==== | ||
| + | |||
| + | Recall: | ||
| + | |||
| + | < | ||
| + | git checkout [< | ||
| + | Overwrite paths in the working tree by replacing with the | ||
| + | contents in the index or in the < | ||
| + | commit). When a < | ||
| + | the < | ||
| + | working tree. | ||
| + | </ | ||
| + | |||
| + | To restore file from HEAD: | ||
| + | |||
| + | < | ||
| + | $ git checkout HEAD -- < | ||
| + | </ | ||
| + | |||
| + | To restore file from index: | ||
| + | |||
| + | < | ||
| + | $ git checkout -- < | ||
| </ | </ | ||