简体   繁体   English

改变git结构

[英]Change git structure

Currently I have the following folder structure: 当前,我具有以下文件夹结构:

root
  .git (folder)
  Folder A
     SubFolderA
     ...
  Folder B
  ...

And I want the following structure: 我想要以下结构:

root
  Folder A
    .git (folder)
     SubFolderA
     ...
  Folder B
  ...

How can I do this without destroy my current repo? 如何在不破坏我当前回购的情况下做到这一点?

Thanks in advance. 提前致谢。

If you really want that, then go ahead and move it: 如果您真的想要,请继续进行以下操作:

$ mv .git FolderA/
$ cd FolderA/
$ git add .

But notice how all files in FolderB will now be out of source control: 但是请注意, FolderB所有文件现在将如何脱离源代码控制:

$ git commit -m "Remove all but FolderA from source control"
[master d044479] Remove all but FolderA from source control
 10 files changed, 5 deletions(-)
 rename FolderA/FileInA1 => FileInA1 (100%)
 rename FolderA/FileInA2 => FileInA2 (100%)
 rename FolderA/FileInA3 => FileInA3 (100%)
 rename FolderA/FileInA4 => FileInA4 (100%)
 rename FolderA/FileInA5 => FileInA5 (100%)
 delete mode 100644 FolderB/FileInB1
 delete mode 100644 FolderB/FileInB2
 delete mode 100644 FolderB/FileInB3
 delete mode 100644 FolderB/FileInB4
 delete mode 100644 FolderB/FileInB5

You don't have to worry about these other files if you want to read them later, their history is not lost. 如果您以后要阅读它们,则不必担心这些其他文件,它们的历史记录也不会丢失。

For example, if you decide to roll back this commit you can always do that: 例如,如果您决定回滚此提交,则可以始终这样做:

$ git reset --hard @^

Notice how this will recreate a second copy of FolderB under FolderA/FolderB : 请注意,这将如何在FolderA/FolderB下重新创建FolderB的第二个副本:

..
├── FolderA
│   ├── FolderA
│   │   ├── FileInA1
│   │   ├── FileInA2
│   │   ├── FileInA3
│   │   ├── FileInA4
│   │   └── FileInA5
│   └── FolderB
│       ├── FileInB1
│       ├── FileInB2
│       ├── FileInB3
│       ├── FileInB4
│       └── FileInB5
└── FolderB
    ├── FileInB1
    ├── FileInB2
    ├── FileInB3
    ├── FileInB4
    └── FileInB5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM