我有一个带有多个目录的git repo,还有一个文件,MyFile.ext

/
  LargeDir1/
  LargeDir2/
  LargeDir3/
      .
      .
      .
  MyFile.ext

我想启动一个只有MyFile.ext的新回购协议,并保留所有与之相关的历史记录,但忽略所有其他内容(所有LargeDir的内容)。我该怎么做?
对于目录,我已经成功地使用了this answer,但是我在一个文件上尝试过,但它不起作用。
我也试过this answer,它确实删除了除我的文件之外的所有内容,但它似乎也留下了所有的历史。

最佳答案

使用git fast-export
首先,将文件的历史记录导出到快速导入流。确保在master分支上执行此操作。

cd oldrepo
git fast-export HEAD -- MyFile.ext >../myfile.fi

然后创建一个新的repo并导入。
cd ..
mkdir newrepo
cd newrepo
git init
git fast-import <../myfile.fi
git checkout

关于git - 如何将单个文件从git存储库拆分为新存储库?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39479154/

10-14 15:52
查看更多