@0x-lerna-fork/import 中文文档教程
@0x-lerna-fork/import
使用提交历史将包导入 monorepo
安装 lerna 以访问 lerna
CLI。
Usage
$ lerna import <path-to-external-repository>
在
导入包,包含提交历史, 进入 packages/
。 原始提交作者、日期和消息 被保存下来。 提交应用于当前分支。
这对于将预先存在的独立包收集到 Lerna 中很有用 回购。 每个提交都被修改以进行相对于包的更改 目录。 因此,例如,添加 package.json
的提交将 而是添加 packages/
。
注意:如果您要在新的 lerna 存储库上导入外部存储库,请记住至少进行一次提交。
# Getting started with Lerna
$ git init lerna-repo && cd lerna-repo
$ npx lerna init
$ npm install
# Adding a commit
$ git add .
$ git commit -m "Initial lerna commit" # Without a commit, import command would fail
# Importing other repository
$ npx lerna import <path-to-external-repository>
Options
--flatten
当导入带有冲突的合并提交的存储库时,导入命令将无法尝试应用所有提交。 用户可以使用此标志来请求导入“平面”历史,即每次合并提交都作为合并引入的单个更改。
$ lerna import ~/Product --flatten
--dest
导入仓库时,可以通过lerna.json中列出的目录指定目标目录。
$ lerna import ~/Product --dest=utilities
--preserve-commit
每个 git 提交都有一个作者和一个提交者(每个都有一个单独的日期)。 通常他们是同一个人(和日期),但是由于 lerna import
从外部存储库重新创建每个提交,committer 成为当前的 git 用户(和日期). 这在技术上是正确的,但可能并不理想,例如,在 Github 上,如果他们是不同的人,它会同时显示作者 和提交者 ,导致对导入的提交可能造成混淆的历史/指责。
启用此选项会保留原始的提交者(和提交日期)以避免此类问题。
$ lerna import ~/Product --preserve-commit
@0x-lerna-fork/import
Import a package into the monorepo with commit history
Install lerna for access to the lerna
CLI.
Usage
$ lerna import <path-to-external-repository>
Import the package at <path-to-external-repository>
, with commit history, into packages/<directory-name>
. Original commit authors, dates and messages are preserved. Commits are applied to the current branch.
This is useful for gathering pre-existing standalone packages into a Lerna repo. Each commit is modified to make changes relative to the package directory. So, for example, the commit that added package.json
will instead add packages/<directory-name>/package.json
.
Note: If you're importing an external repository on a new lerna repository, then do remember to have at least one commit.
# Getting started with Lerna
$ git init lerna-repo && cd lerna-repo
$ npx lerna init
$ npm install
# Adding a commit
$ git add .
$ git commit -m "Initial lerna commit" # Without a commit, import command would fail
# Importing other repository
$ npx lerna import <path-to-external-repository>
Options
--flatten
When importing repositories with merge commits with conflicts, the import command will fail trying to apply all commits. The user can use this flag to ask for import of "flat" history, i.e. with each merge commit as a single change the merge introduced.
$ lerna import ~/Product --flatten
--dest
When importing repositories, you can specify the destination directory by the directory listed in lerna.json.
$ lerna import ~/Product --dest=utilities
--preserve-commit
Each git commit has an author and a committer (with a separate date for each). Usually they're the same person (and date), but since lerna import
re-creates each commit from the external repository, the committer becomes the current git user (and date). This is technically correct, but may be undesireable, for example, on Github, which displays both the author and committer if they're different people, leading to potentially confusing history/blames on imported commits.
Enabling this option preserves the original committer (and commit date) to avoid such issues.
$ lerna import ~/Product --preserve-commit