GIT:如何在不覆盖当前提交的情况下检出先前提交的文件?
之前的几次提交我让一些 javascript 以一种方式工作.在几次提交的过程中,我现在让它以另一种方式工作.我想查看该文件,因为它是几次提交前的,因为我可能想在新的 javascript 中使用它的某些方面.但是我不想将我当前的文件恢复到原来的样子.我只是想从字面上打开旧文件,看看它,然后将其中的一些代码复制并粘贴到新文件中.
Several commits previously I had some javascript working one way. Over the course of several commits I now have it working another way. I would like to look at the file as it was several commits ago because I might want to use aspects of it in the new javascript. However I don't want to revert my current file to exactly what it was. I just want to literally open the old file, have a look around it and maybe copy and paste some code from it into the new file.
如何在不覆盖最新版本的情况下从先前提交中检索文件副本?
How do I retrieve a copy of the file from a previous commit without overwriting the most recent version?
只需将 git show
的输出重定向到一个文件.
Simply redirect the output of git show
to a file.
git show *SHA-of-old-commit*:*filename* > newfilename
例如:
git show 7c4eacc:main.cpp > main.cpp.old