Skip to content

Commit 93bfdfb

Browse files
authored
cheat sheet: Suggest git-restore for discarding changes (#2079)
In modern versions of Git, `git status` will suggest using `git restore` in these cases. Also, in all other instances, the cheat sheet already lists `git switch` or `git restore` alternatives to `git checkout`. ## Changes <!-- List the changes this PR makes. --> - Add `git restore <file>` and `git restore --staged --worktree <file>` as alternatives to `git checkout <file>` and `git checkout HEAD <file>`, respectively. ## Context Make the cheat sheet more consistent with `git status`. Also, when teaching Git to new users, using `git switch` and `git restore` consistently in place of `git checkout` arguably makes common workflows easier to understand; and being able to point those new users to the official cheat sheet without introducing new commands would be a big bonus.
2 parents ba2e629 + 30cca90 commit 93bfdfb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

content/cheat-sheet/_index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ <h2 id="ways-to-refer-to-a-commit">Ways to refer to a commit</h2>
212212
<h2 id="discard-your-changes">Discard Your Changes</h2>
213213
<div class="item">
214214
<h3>Delete unstaged changes to one file:</h3>
215+
<code>git restore &lt;file&gt;</code>
216+
<span class="or">OR</span>
215217
<code>git checkout &lt;file&gt;</code>
216218
</div>
217219
<div class="item">
218220
<h3>Delete all staged and unstaged changes to one file:</h3>
221+
<code>git restore --staged --worktree &lt;file&gt;</code>
222+
<span class="or">OR</span>
219223
<code>git checkout HEAD &lt;file&gt;</code>
220224
</div>
221225
<div class="item">

0 commit comments

Comments
 (0)