git save last commited version of file.
- User
git save last commited version of file.
- Assistant
Here are a few ways to “go back” or save the last-committed version of a file in Git, depending on what you actually want:
-
Simply discard your local edits and restore the last commit
- Git < 2.23:
bash
git checkout HEAD -- path/to/file.txt - Git ≥ 2.23:
bash
git restore path/to/file.txt
- Git < 2.23:
-
Export the last-committed version to a separate file If you want to keep your working copy but also save the HEAD version elsewhere:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.