Skip to content

Commit 0bfeea6

Browse files
preserving-git-histories.md: Move files _before_ merging (#20289)
Co-authored-by: Isaac Mann <[email protected]>
1 parent 3e63bc0 commit 0bfeea6

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

docs/shared/migration/preserving-git-histories.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,31 @@ Git has some helpful tools for this, and we'll walk through some of the common p
1010

1111
To merge in another project, we'll essentially use the standard `git merge` command, but with a few lesser known options/caveats.
1212

13-
To start we'll add a remote repository url for where the standalone app is located:
13+
If your standalone project was not an Nx workspace, it's likely that your migration work will also entail moving directories to match a typical Nx Workspace structure. You can find more information in the [Manual migration](/recipes/adopting-nx/manual) page, but when migrating an existing project, you'll want to ensure that you use [`git mv`](https://git-scm.com/docs/git-mv) when moving a file or directory to ensure that file history from the old standalone repo is not lost!
14+
15+
In order to avoid merge conflicts later, it's best to first do the folder reorganization in the _standalone project repo_. For example, assuming you want the standalone app to end up at `apps/my-standalone-app` in the monorepo and your main branch is called `master`:
1416

1517
```shell
16-
git remote add my-standalone-app <repository url>
18+
cd my-standalone-app
19+
git fetch
20+
git checkout -b monorepo-migration origin/master
21+
mkdir -p apps/my-standalone-app
22+
git ls-files | sed 's!/.*!!'| uniq | xargs -i git mv {} apps/my-standalone-app
23+
git commit -m "Move files in preparation for monorepo migration"
24+
git push -u
1725
```
1826

19-
Now we must fetch the branches from the new remote
27+
Next, in your monorepo, we'll add a remote repository url for where the standalone app is located:
2028

2129
```shell
30+
git remote add my-standalone-app <repository url>
2231
git fetch my-standalone-app
2332
```
2433

25-
Assuming that our main branch on this repo is called 'master', then we'll run
34+
Then we'll run
2635

2736
```shell
28-
git merge my-standalone-app/master --allow-unrelated-histories
37+
git merge my-standalone-app/monorepo-migration --allow-unrelated-histories
2938
```
3039

3140
Note that without the `--allow-unrelated-histories` option, the command would fail with the message: `fatal: refusing to merge unrelated histories`.
32-
33-
## Merge Conflicts
34-
35-
At this point, it is very likely that you'll have merge conflicts in your root files.
36-
37-
For your `package-lock.json` or `yarn.lock`, it's likely best to remove those entirely and allow a new lock file to be generated by installing when the merge is complete.
38-
39-
For other files (think `nx.json`, `project.json`, `angular.json`, `package.json`, `tsconfig.base.json`, etc.) you'll need to resolve these conflicts manually to ensure that considerations for both your existing workspace and the newly added project are accounted for.
40-
41-
Note that for these files, the file history of the standalone project will not be present after merging. You would see all changes from resolving conflicts in the single merge commit, and any further back would simply be the file history of your workspace.
42-
43-
## Using `git mv`
44-
45-
If your standalone project was not an Nx workspace, it's likely that your migration work will also entail moving directories to match a typical Nx Workspace structure. You can find more information in the [Manual migration](/recipes/adopting-nx/manual) page, but when migrating an existing project, you'll want to ensure that you use [`git mv`](https://git-scm.com/docs/git-mv) when moving a file or directory to ensure that file history from the old standalone repo is not lost!

0 commit comments

Comments
 (0)