Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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] rpjdaygit_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 what you just did.
  
 ===== The state of files ===== ===== The state of files =====
Line 27: Line 27:
 ==== Undoing unstaged changes (part one) ==== ==== Undoing unstaged changes (part one) ====
  
-From ''man git-checkout'':+Say you've made some local changes, but have staged nothing so far. From ''man git-checkout'':
  
 <code> <code>
Line 44: Line 44:
 </code> </code>
  
-To undo //all// unstaged changes:+To undo //all// unstaged changes throughout the working tree:
  
 <code> <code>
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 (unstagedchanges, see above.+If you have already staged some changes, then made //additional// changes and want to undo //only// those additional, unstaged changes, see above -- it works the same way.
  
 <code> <code>
Line 79: Line 79:
 </code> </code>
  
-End result:+End result -- your unstaged changes are lost, while the staged changes in the index are right where you left them.
  
 <code> <code>
Line 110: Line 110:
 </code> </code>
  
-Recall how to do this for everything:+Recall how to do this for everything in the working tree:
  
 <code> <code>
 $ git reset --hard $ git reset --hard
 +</code>
 +
 +==== Unstaging staged content ====
 +
 +From ''man git-reset'':
 +
 +<code>
 +       git reset [<mode>] [<commit>]
 +
 +       ...
 +
 +           --mixed
 +               Resets the index but not the working tree (i.e., the
 +               changed files are preserved but not marked for commit)
 +               and reports what has not been updated. This is the
 +               default action.
 +</code>
 +
 +Example:
 +
 +<code>
 +$ git reset -- README
 +</code>
 +
 +==== Restoring accidentally-deleted files ====
 +
 +Recall:
 +
 +<code>
 +git checkout [<tree-ish>] [--] <pathspec>...
 +    Overwrite paths in the working tree by replacing with the
 +    contents in the index or in the <tree-ish> (most often a
 +    commit). When a <tree-ish> is given, the paths that match
 +    the <pathspec> are updated both in the index and in the
 +    working tree.
 +</code>
 +
 +To restore file from HEAD:
 +
 +<code>
 +$ git checkout HEAD -- <file>
 +</code>
 +
 +To restore file from index:
 +
 +<code>
 +$ git checkout -- <file>
 </code> </code>
  • git_undoing_things.1551182687.txt.gz
  • Last modified: 2019/02/26 12:04
  • by rpjday