Git:以新名称签出目录的旧版本 [英] Git: Checkout old version of directory under new name

查看:104
本文介绍了Git:以新名称签出目录的旧版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用新名称签出目录的先前版本?

How do I check out a previous version of a directory under a new name?

(我在仓库中始终有一个目录foo.我想在我当前的工作树中创建一个目录foo_old,其内容为HEAD~2:foo的目录.我同时需要两个版本,为了确保它们给出相同的结果,进行测试需要大量代码,并且需要同时提供两个结果(例如,结果并非简单地是整数),所以我不能简单地临时签出HEAD~2来做什么我想要)

(I have and always had a directory foo in my repo. I want to create a directory foo_old in my current working tree whose contents are those of HEAD~2:foo. I need both versions at the same time, to make sure they give the same results, testing this requires quite a bit of code and requires having both results available at the same time (the results are not simply integers, say), so I cannot simply checkout HEAD~2 temporarily to do what I want)

此问题问如何以新名称签出文件的先前版本,但是不能将接受的答案推广到目录.

This question asks how to check out a previous version of a file under a new name, but the accepted answer cannot be generalized to directories.

推荐答案

您可以做得很简单:

git co -b new-branch-name    # create and go to new branch, just to be sure
git slg                      # get the commit hash you need for next step
git co [commit-hash]         # now you get the old folder by the state you need it

然后将所需目录复制到桌面. (您现在处于HEAD分离状态)

then copy the directory you need to your desktop. ( You are now in HEAD detached)

git co new-branch-name       # cause you are in detached head go back to new-branch

在桌面上,将目录重命名为foo_old,然后将其复制粘贴到项目中所需的位置.

On desktop rename the directory to foo_old and copy paste it to where you need it in project.

这篇关于Git:以新名称签出目录的旧版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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