- Find the commits that changed the file
git log --oneline -- src/app.jsEach line is one commit that touched this file, newest first. Copy the short ID of the version you want.
- Look at the file as it was in that commit
git show a1b2c3d:src/app.jsOnly shows it. Nothing changes yet. Press q to leave.
- Bring that version back
git restore --source a1b2c3d -- src/app.jsOnly this one file changes. Everything else stays as it is now.
- Commit the old version
git commit -am "Restore src/app.js from a1b2c3d"
Check it worked
- Check what changed in the file
git diff HEAD~1 -- src/app.js
Undo it
- Before you commit: go back to the latest version
git restore --source HEAD -- src/app.jsAfter you commit, undo the last commit instead.
- Find the commits that changed the file
git log --oneline -- src/app.jsEach line is one commit that touched this file, newest first. Copy the short ID of the version you want.
- Look at the file as it was in that commit
git show a1b2c3d:src/app.jsOnly shows it. Nothing changes yet. Press q to leave.
- Bring that version back
git restore --source a1b2c3d -- src/app.jsOnly this one file changes. Everything else stays as it is now.
- Commit the old version
git commit -am "Restore src/app.js from a1b2c3d"
Check it worked
- Check what changed in the file
git diff HEAD~1 -- src/app.js
Undo it
- Before you commit: go back to the latest version
git restore --source HEAD -- src/app.jsAfter you commit, undo the last commit instead.
- Find the commits that changed the file
git log --oneline -- src/app.jsEach line is one commit that touched this file, newest first. Copy the short ID of the version you want.
- Look at the file as it was in that commit
git show a1b2c3d:src/app.jsOnly shows it. Nothing changes yet. Press q to leave.
- Bring that version back
git restore --source a1b2c3d -- src/app.jsOnly this one file changes. Everything else stays as it is now.
- Commit the old version
git commit -am "Restore src/app.js from a1b2c3d"
Check it worked
- Check what changed in the file
git diff HEAD~1 -- src/app.js
Undo it
- Before you commit: go back to the latest version
git restore --source HEAD -- src/app.jsAfter you commit, undo the last commit instead.