Git cherry-pick code synchronization between multiple git project repositories

During this time, the code separation between the projects was done, from the A library on git to the B library, and then the A library and the B library were developed independently for their own requirements.

In this way, the code at the beginning of the A library and the B library is basically the same, but a problem is encountered. Sometimes the code of the A library is BUG modified and needs to be modified in the B library, which is not convenient.

Therefore, try to see if cherry-pick is feasible.

 

After reading some predecessor articles and starting to try, (take a commit-->commit id is XXXXX of the release of library A and submit it to the release branch of library B as an example) The steps are as follows:

  1. Cut the code to the release branch of the B library. To prevent problems, it is recommended to pull a backup branch first.

  2. Add another warehouse A locally

 Zxxxxx5:B 1$ git remote add zhorigin http://git.xxxx.com/A.git

You can check whether the addition is successful through git remote -v
Zxxxxx5:B 1$ git remote -v
origin http://git.xxxx.com/B.git (fetch)
origin http://git.xxxx.com/B.git (push)
zhorigin http://git.xxxx.com/A.git (fetch)
zhorigin http://git.xxxxcom/A.git (push)
 

  3. Zxxxxx5: B 1$ git fetch zhorigin   will synchronize the branch information of the remote A library to the local

  4. At this time, you can cherry-pick. If you encounter relevant prompts, just follow the prompts.

    Zxxxxx5:B 1$ git cherry-pick ac50e25bf

on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
    git config --global --edit
After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author

---------------------------------------------------------------
---------------------------------------------------------------

Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
    git config --global user.name "Your Name"
    git config --global user.email [email protected]
After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author
 

 

 

 5. The above prompt, after the operation, you can git push. At this time, a magical scene appears. Clone the BUG branch of the A library to the B library, (if you are in the release branch of the A library If you modify it directly, you may directly push to the release of the B library. If you are interested, you can try it)

Zxxxxx5:B 1$ git push
Enumerating objects: 69, done.
Counting objects: 100% (69/69), done.
Delta compression using up to 8 threads
Compressing objects: 100% (20/20), done.
Writing objects: 100% (39/39), 4.01 KiB | 2.00 MiB/s, done.
Total 39 (delta 13), reused 10 (delta 3)
To http://git.xxxx.com/B.git
   ccccc..yyyyyy  bugfix-branch-xxxx-A -> bugfix-branch-xxxx-A
 

6. So far, the BUG modification branch of library A has been in library B, and the subsequent process is simple, the same as the ordinary cherry-pick process

   Locally make sure to switch to the release of the B library

  Zxxxxx5:B 1$ git checkout release
  Zxxxxx5:B 1$ git cherry-pick yyyyyy

  Zxxxxx5:B 1$ git push

7. Remove remove to avoid affecting normal code operations

 Zxxxxx5:B 1$ git remote -v
origin  http://git.xxxx.com/B.git (fetch)
origin  http://git.xxxx.com/B.git (push)
zhorigin        http://git.xxxx.com/A.git (fetch)
zhorigin        http://git.xxxxcom/A.git (push)
 Zxxxxx5:B 1$ git remote remove zhorigin
 Zxxxxx5:B 1$git remote -v
origin  http://git.xxxx.com/B.git (fetch)
origin  http://git.xxxx.com/B.git (push)

 

 

Remarks:

     There are some details, which are very interesting, such as why the clone of A library branches to the B library, why the starting commit id of the new branch version is ccccc, etc.

Guess you like

Origin blog.csdn.net/pan0755/article/details/108220934