GIT:如何在不覆盖当前提交的情况下检出先前提交的文件? [英] GIT: How to checkout a file from a previous commit without overwriting the current one?

查看:30
本文介绍了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

这篇关于GIT:如何在不覆盖当前提交的情况下检出先前提交的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆