改变git结构

时间:2017-05-14 09:29:22

标签: git version-control repository

目前我有以下文件夹结构:

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

我想要以下结构:

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

如何在不破坏现有回购的情况下执行此操作?

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果你真的想要,那就继续前进吧:

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

但请注意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

如果您想稍后阅读这些文件,则不必担心这些其他文件,其历史记录不会丢失。

例如,如果您决定回滚此提交,则可以始终执行此操作:

$ git reset --hard @^

请注意这将如何在FolderB下重新创建FolderA/FolderB的第二个副本:

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