Patching from MonoRepos in Git
Patch Patch, someone is there waiting for your commits.
Problem Statement:
Let us say you have one project working on, and the mono repo holds that project directory inside it. Now you have kind of 20 commits inside the sub repo(your project repo) of the mono repo from different teams, and you want those 20 commits changes to get merged in your project repo.
Understand like this —
Project1:
->Project Repo(Repo1)
Project2:
->Mono Repo (Repo2)
>>>>ABC Repo
>>>>XYZ Repo
>>>> Project Repo
Although there is one way of manually applying your changes when ChatGPT is killing, should we consider this approach?
Not at all
So consider the below example —
— Example:
Repo1, you have been working
Repo2 holds Repo1(Sub Repo). Repo1 history has 20 commits inside it, and now you want all the changes to get applied in the Repo1 you are working on (your project Repo).
Clone Mono Repo in your working directory. Develop the branch you have been looking into,
git -c http.sslVerify=false clone https://REPO2
git checkout develop
git -c http.sslVerify=false pull
Use the below command if there is any SSL-related error there.
-c http.sslVerify=false
Inside mono repo
git format-patch 20 Repo2(subrepo)
It will generate 20 different patches for 20 commits.
In your case, what would it be?
In your case, Check the last date when files were merged and count the commits from that date to the latest commit.
And then go to your working project branch —
git clone https://Repo1
git pull origin main
Make a new branch —
The example below: New branch will diverge to
git checkout -b #3983
If in IDE, apply those patches one by one to ensure nothing breaks in the build, or you can use patch apply commands from the terminal in one go. As this shown below:
patch -p1 < 00001-whatever.patch
or
patch -p1 < 00001*.patch
or use
git am *.
And if there are conflicts, you need to check them and resolve them manually. On applying patches, conflicts come in the form of hunks.
Ultimately, ensure that Repo1 is holding all our changes and working fine.
In the end, you can use —
git add -all
git commit -m "message"
git push your_branch
Note: For the above problem, CVS from the RemoteIndian community helped me figure out the solution, and I am grateful to the universe.
Thank You!!