To revet file(s) to previous commit, run the following command:
git checkout <commit-hash> -- <path/to/file1> <path/to/file2>
# suppose the commit hash is 3b576dc
git checkout 3b576dc -- foo.js src/bar.js
# one commit before 3b576dc
git checkout 3b576dc~1 -- foo.js src/bar.js
For git >= 2.23, run the following command:
git restore --source=<commit-hash> <path/to/file1> <path/to/file2>
# suppose the commit hash is 3b576dc
git restore --source=3b576dc foo.js src/bar.js
# one commit before 3b576dc
git restore --source=3b576dc~1 foo.js src/bar.js
References #
https://stackoverflow.com/questions/215718/how-do-i-reset-or-revert-a-file-to-a-specific-revision
Tags
git🙏🙏🙏
Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖!
Published