在
master
分支上,我有一个包含文件的新版本文件夹,例如:config
- db
- rdbms
- postgres.conf
- redis.conf
- nosql
- mongo.conf
- web
- apache.conf
- security.conf
我需要获取这些文件的旧版本,并将它们添加到主代码库中,但顶层文件夹 config
应该重命名为 config-old
,以便同时存在 config
和 config-old
:
config
- db
- rdbms
- postgres.conf
- redis.conf
- nosql
- mongo.conf
- web
- apache.conf
- security.conf
config-old
- db
- rdbms
- postgres.conf
- redis.conf
- nosql
- mongo.conf
- web
- apache.conf
- nginx.conf
我知道如何使用git show
或git cat-file
恢复单个文件,并使用shell重定向将它们保存在另一个名称下,但如何对整个文件夹及其所有子文件夹/子文件进行操作呢?
显然,我可以切换到所需的分支/版本,将文件夹复制到git根目录之外的某个地方,然后切换回主分支并将其以不同的名称复制回来,但我想知道是否可以使用git本身完成此操作?
config/
中有.gitignore
文件,请小心使用此方法。这些文件也将被复制,并可能因为其.gitignore
模式仅限于其原始文件夹而意外跟踪。此外,如果git status
不干净,您可能会遇到问题(检出取消)。 - Jay