Multi-branch code synchronization method and device and computer program product

By preset code synchronization configuration files to split the different code into fragments and synchronize independently, the inconvenience and high failure rate of traditional multi-branch code synchronization is solved, and efficient and reliable code synchronization is achieved.

CN120407004APending Publication Date: 2025-08-01LISHENG AUTOMOBILE TECHNOLOGY (GUANGZHOU) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510466223.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

The traditional manual multi-branch code synchronization method is cumbersome to operate, prone to errors, and has a high synchronization failure rate. It lacks automated solutions and cannot meet the requirements of efficiency and accuracy.

Method used

Synchronize the configuration file by preset code, split the difference code into multiple code snippets, and use configuration item matching and synchronization to process each fragment independently to ensure the accuracy and success rate of synchronization operations.

Benefits of technology

It significantly improves the success rate of multi-branch code synchronization, solves the inconvenience and high failure rate of traditional manual synchronization, and achieves efficient and reliable code synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407004A_ABST
    Figure CN120407004A_ABST
Patent Text Reader

Abstract

The invention relates to a multi-branch code synchronization method and device and a computer program product, and the method comprises the steps: obtaining a branch name in a combined code lading bill and a difference code before and after modification when a code management platform receives the combined code lading bill; converting the difference code into a plurality of pieces of code snippet information; a preset code synchronization configuration file is obtained, the code synchronization configuration file comprises at least one code configuration item, and the code configuration item comprises a configuration item name, a branch name list and a code snippet feature; traversing code configuration items in the code synchronization configuration file, and if any code configuration item is matched with any code snippet information obtained by conversion, determining a to-be-synchronized branch according to a branch name and a branch name list of the code configuration item, and synchronizing the corresponding code text of the branch to be synchronized according to the information of any code snippet. Multi-branch code synchronization is carried out based on the method, and the problems of inconvenience and high failure rate of traditional manual synchronization of multi-branch codes can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of code management and version control in multi-software development, and particularly relates to a multi-branch code synchronization method, apparatus, and computer program product. Background Art

[0002] In the field of code management and version control in software development, Git servers and Git-based code management platforms (such as GitHub, GitLab, etc.) have become mainstream tools. These platforms support distributed version control, allowing developers to have a complete local mirror of the code repository, including historical records, thus avoiding the problem of single-point failure of the central server. In addition, the Git platform also supports multi-branch development, allowing different teams or developers to develop on independent branches to meet different business needs.

[0003] However, with the increasing complexity of software projects, multi-branch development brings new challenges. Especially when code needs to be synchronized from one branch to multiple other branches, the traditional manual synchronization (such as cherry-pick) method has the following problems:

[0004] (1) Inconvenience of manual synchronization;

[0005] In multi-branch development, developers need to frequently synchronize code from one branch to other branches. The traditional manual synchronization method (such as cherry-pick) is cumbersome and error-prone, especially when dealing with large code change sets involving multiple file and function modifications.

[0006] (2) High synchronization failure rate;

[0007] The existing cherry-pick method is prone to failure when there are changes in the code context. For example, when a code change set involves modifications to multiple files and functions, as long as there is a change in the context of one piece of code, it may lead to synchronization failure.

[0008] (3) Lack of automated solutions;

[0009] Although current code management platforms perform well in version control and branch management, they still lack in the automation of multi-branch code synchronization. Existing automated tools often fail to meet the requirements of high efficiency and accuracy when dealing with complex code synchronization tasks. Summary of the Invention

[0010] The purpose of this application is to propose a multi-branch code synchronization method, apparatus, and computer program product to solve the inconvenience and high failure rate problems of traditional manual synchronization of multi-branch code.

[0011] To achieve the above object, according to the first aspect of the present application, a multi-branch code synchronization method is provided, including:

[0012] When the code management platform receives a code merge bill of lading, obtain the branch name in the code merge bill of lading and the differential code before and after the modification;

[0013] Convert the differential code into a number of code segment information;

[0014] Obtain a preset code synchronization configuration file, the code synchronization configuration file includes at least one code configuration item, and the code configuration item includes a configuration item name, a branch name list, and a code segment feature;

[0015] Traverse the code configuration items in the code synchronization configuration file. If any code configuration item matches any of the converted code segment information, determine the branches to be synchronized according to the branch name and the branch name list of any of the code configuration items, and synchronize the corresponding code text of the branches to be synchronized according to any of the code segment information.

[0016] According to the second aspect of the present application, a multi-branch code synchronization device is provided, including:

[0017] A differential code acquisition module, configured to obtain the branch name in the code merge bill of lading and the differential code before and after the modification when the code management platform receives a code merge bill of lading;

[0018] A code segment conversion module, configured to convert the differential code into a number of code segment information;

[0019] A configuration file acquisition module, configured to obtain a preset code synchronization configuration file, the code synchronization configuration file includes at least one code configuration item, and the code configuration item includes a configuration item name, a branch name list, and a code segment feature;

[0020] A code segment synchronization module, configured to traverse the code configuration items in the code synchronization configuration file. If any code configuration item matches any of the converted code segment information, determine the branches to be synchronized according to the branch name and the branch name list of any of the code configuration items, and synchronize the corresponding code text of the branches to be synchronized according to any of the code segment information.

[0021] According to the third aspect of the present application, a multi-branch code synchronization device is provided, including:

[0022] A communication interface, configured to communicate with other electronic devices;

[0023] A memory, configured to store computer program instructions;

[0024] A processor for executing the computer program instructions to support the multi-branch code synchronization device to implement the method as described above.

[0025] According to a fourth aspect of the present application, there is provided a computer program product, characterized in that it includes computer program instructions, and the computer program instructions direct a computer device to perform operations corresponding to the method as described above.

[0026] The multi-branch code synchronization method, device, and computer program product proposed in the present application have the following beneficial effects:

[0027] Pre-set matching code synchronization configuration items for each code segment in advance, including at least one code configuration item, and the code configuration item includes a configuration item name, a list of branch names, and code segment features; when a code merge bill of lading is submitted, extract the differential code in the code merge bill of lading, and split the differential code into multiple small code segments, and these code segments may be distributed in different files and code paths; for each code segment, perform synchronization operations separately according to its corresponding synchronization configuration item. Even if a certain segment encounters conflicts or problems, it will not affect the synchronization of other segments, thereby significantly improving the overall synchronization success rate and effectively solving the inconvenience and high failure rate problems of traditional manual synchronization of multi-branch codes. Description of the Drawings

[0028] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required in the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0029] Figure 1 It is a flowchart of a multi-branch code synchronization method in an embodiment of the present application.

[0030] Figure 2 It is a framework diagram of a multi-branch code synchronization device in another embodiment of the present application. Detailed Description of the Embodiments

[0031] The detailed description of the drawings is intended to be an illustration of the current embodiments of the present application, rather than an indication of the only form in which the present application can be implemented. It should be understood that the same or equivalent functions can be completed by different embodiments intended to be included within the spirit and scope of the present application.

[0032] Refer to Figure 1 , an embodiment of the present application provides a multi-branch code synchronization method, including the following steps:

[0033] Step S10: When the code management platform receives a code merge bill of lading, obtain the branch name in the code merge bill of lading and the differential code before and after the modification.

[0034] Specifically, when the code management platform receives a code merge bill of lading, trigger the hook script pre-arranged by the code platform or trigger the task script pre-arranged by the CI platform (such as jenkins). The hook script or the task script runs automatically, extracts the branch name in the code merge bill of lading and the differential code before and after the modification, and executes steps S20 to S40.

[0035] Step S20: Convert the differential code into several code snippet information.

[0036] Specifically, split the differential code obtained in step S10 into multiple independent code snippets. These code snippets may be divided by file or according to features such as the functional modules and paths of the code. Each code snippet contains sufficient information for matching and synchronization in subsequent steps.

[0037] Step S30: Obtain a preset code synchronization configuration file. The code synchronization configuration file includes at least one code configuration item. The code configuration item includes a configuration item name, a branch name list, and a code snippet feature.

[0038] Specifically, the code synchronization configuration file is a predefined file that contains the rules and parameters for synchronization operations. The code synchronization configuration file contains at least one code configuration item. The number of code configuration items is specifically determined according to the actual situation of the software project. The configuration item name is used to distinguish different configuration items. The branch name list includes the branch names of multiple branches with the same code snippet. The code snippet feature is used to distinguish different code snippets.

[0039] Step S40: Traverse the code configuration items in the code synchronization configuration file. If any code configuration item matches any of the code snippet information obtained by conversion, determine the branches to be synchronized according to the branch name and the branch name list of any of the code configuration items, and synchronize the corresponding code snippet of the branches to be synchronized with any of the code snippet information.

[0040] Specifically, traverse each code configuration item in the configuration file, match each code snippet obtained based on the differential code with each code configuration item. If the feature of a certain code snippet obtained based on the differential code matches the feature of a code snippet in a certain code configuration item, and the branch name of the bill of lading is included in the branch name list of the configuration item, then determine that the code snippet needs to be synchronized to the other branches in the branch name list; further, perform a synchronization operation on the corresponding code snippet on the branch to be synchronized and the code snippet in the bill of lading.

[0041] For example, assume that the branch list is {Branch 1, Branch 2, Branch 3}, the branch name in the merged code bill of lading is Branch 1, the extracted code snippet is Snippet 1, and Snippet 1 matches the code snippet feature in the configuration item. Then, Snippet 1 will be synchronized to the corresponding code snippets of Branch 2 and Branch 3 to complete the code snippet synchronization operation between Branches 1 to 3.

[0042] In summary, the method of this embodiment presets a matching code synchronization configuration item for each code snippet in advance, including at least one code configuration item. The code configuration item includes a configuration item name, a branch name list, and a code snippet feature. When a merged code bill of lading is submitted, the differential code in the merged code bill of lading is extracted and split into multiple small code snippets, which may be distributed in different files and code paths. For each code snippet, a synchronization operation is performed separately according to its corresponding synchronization configuration item. Even if a certain snippet encounters a conflict or problem, it will not affect the synchronization of other snippets, thus significantly improving the overall synchronization success rate and effectively solving the inconvenience and high failure rate problems of traditional manual synchronization of multi-branch code.

[0043] In some embodiments, the code snippet information includes a code snippet feature and the start and end line numbers of the code snippet. The code snippet feature includes a code snippet type and a code snippet path;

[0044] Specifically, the code snippet type may be the language type of the code snippet. The code snippet path generally includes a folder path, a file name, and a function name. To describe the code snippet of an entire folder or an entire file, a wildcard * can be used, such as "folder path / *", "folder path / file name / *";

[0045] Synchronizing the corresponding code text of the branch to be synchronized according to any one of the code snippet information includes:

[0046] Extracting the corresponding code text from the code snippet information according to the code snippet path and the start and end line numbers of the code snippet in the code snippet information; and determining the code text to be synchronized in the branch to be synchronized according to the code snippet type and the code snippet path, and replacing the code text to be synchronized with the extracted code text.

[0047] Specifically, locate the specific file in the project according to the file path provided in the code snippet information, and then use the start line number and end line number provided in the code snippet information to determine the code section to be extracted in the file. After determining the code text to be extracted, it is necessary to find the corresponding position in the branch to be synchronized to replace the code. Again, use the file path in the code snippet information to locate the same file in the branch to be synchronized. According to the type and path of the code snippet, as well as the start and end line numbers, find the corresponding position in the file of the branch to be synchronized. This position is the "code text to be synchronized"; finally, the script will replace the code text to be synchronized found in the branch to be synchronized with the previously extracted code text.

[0048] Through this process, the changes to specific code snippets can be accurately applied to the target branch without affecting other parts of the code. This method can effectively solve merge conflicts and make code synchronization more efficient and reliable.

[0049] In some embodiments, the method further includes:

[0050] After completing the replacement of the code snippet in any branch to be synchronized, generate a corresponding code change bill of lading and submit it to the code management platform.

[0051] Specifically, once the code snippet is successfully replaced in the branch to be synchronized, a code change bill of lading will be created. This bill of lading records all the details of the changes, including which files are modified, which lines are added or deleted, etc.

[0052] In some embodiments, the code synchronization configuration file includes multiple repository configuration items, the repository configuration item includes a code configuration list, and the code configuration list includes at least one of the code configuration items.

[0053] Specifically, the following is an example of a configuration file in json format:

[0054]

[0055]

[0056] Specifically, the code synchronization configuration file makes the code synchronization process very flexible and customizable, and the specific parameters of the code synchronization configuration file can be set according to the specific needs of the software development project.

[0057] Refer to Figure 2 , another embodiment of the present application provides a multi-branch code synchronization device, including:

[0058] A differential code acquisition module 1, configured to obtain the branch name and the differential code before and after modification in the incorporated code bill of lading when the code management platform receives the incorporated code bill of lading;

[0059] A code snippet conversion module 2, configured to convert the differential code into a plurality of code snippet information;

[0060] A configuration file acquisition module 3, configured to acquire a preset code synchronization configuration file, where the code synchronization configuration file includes at least one code configuration item, and the code configuration item includes a configuration item name, a branch name list, and a code snippet feature;

[0061] A code snippet synchronization module 4, configured to traverse the code configuration items in the code synchronization configuration file. If any code configuration item matches any one of the converted code snippet information, determine the branch to be synchronized according to the branch name and the branch name list of any one of the code configuration items, and synchronize the corresponding code text of the branch to be synchronized according to any one of the code snippet information.

[0062] In some embodiments, the code snippet information includes a code snippet feature and code snippet start and end line numbers, and the code snippet feature includes a code snippet type and a code snippet path;

[0063] The code snippet synchronization module 4 is configured to:

[0064] Extract the corresponding code text from the code snippet information according to the code snippet path and the code snippet start and end line numbers in the code snippet information; and determine the code text to be synchronized in the branch to be synchronized according to the code snippet type and the code snippet path, and replace the code text to be synchronized with the extracted code text.

[0065] In some embodiments, the device further includes:

[0066] After completing the code snippet replacement of any branch to be synchronized, generate a corresponding code modification bill of lading and submit it to the code management platform.

[0067] In some embodiments, the code synchronization configuration file includes a plurality of repository configuration items, and the repository configuration item includes a code configuration list, and the code configuration list includes at least one of the code configuration items.

[0068] The device in this embodiment corresponds to the method in the above embodiment. Therefore, the content not described in detail in the device in this embodiment can be obtained by referring to the content of the method in the above embodiment, and thus will not be elaborated in this embodiment.

[0069] Another embodiment of the present application further provides a multi-branch code synchronization device, including:

[0070] A communication interface, configured to communicate with other electronic devices;

[0071] A memory, configured to store computer program instructions;

[0072] A processor for executing the computer program instructions to support the multi-branch code synchronization device to implement the method as described above.

[0073] In this embodiment, the memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function, etc., and the data storage area can store relevant data, etc. In addition, the memory can be a high-speed random access memory, or a non-volatile memory, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a FlashCard, etc., or the memory can also be other volatile solid-state storage devices.

[0074] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor, or the processor can also be any conventional processor. The processor is the control center of the device, connecting various parts of the device using various interfaces and lines.

[0075] Another aspect of this application also provides a computer program product, including computer program instructions, and the computer program instructions direct a computer device to perform operations corresponding to the method as described above.

[0076] Specifically, the computer program product includes a series of computer program instructions. These computer program instructions are the code written in the computer program, which define how to perform specific operations. These computer program instructions are designed to be loaded onto a computer device and guide the device to perform specific operations, which refer to the various steps in the method described in the above embodiments. In this way, the computer program product of this embodiment provides a complete software solution, which can run on various computer devices and implement the method of the above embodiments.

[0077] The embodiments of the present application have been described above. The above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations are obvious to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to technologies in the market, or to enable other ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A multi-branch code synchronization method, characterized in that Including: When the code management platform receives a code merge bill of lading, obtain the branch name in the code merge bill of lading and the differential code before and after modification; Convert the differential code into a number of code snippet information; Obtain a preset code synchronization configuration file, where the code synchronization configuration file includes at least one code configuration item, and the code configuration item includes a configuration item name, a branch name list, and a code snippet feature; Traverse the code configuration items in the code synchronization configuration file. If any code configuration item matches any of the converted code snippet information, determine the branch to be synchronized according to the branch name and the branch name list of the any code configuration item, and synchronize the corresponding code text of the branch to be synchronized according to the any code snippet information.

2. The method according to claim 1, characterized in that, The code snippet information includes a code snippet feature and the start and end line numbers of the code snippet, and the code snippet feature includes a code snippet type and a code snippet path; The synchronizing the corresponding code text of the branch to be synchronized according to the any code snippet information includes: Extract the corresponding code text from the code snippet information according to the code snippet path and the start and end line numbers of the code snippet in the code snippet information; and determine the code text to be synchronized in the branch to be synchronized according to the code snippet type and the code snippet path, and replace the code text to be synchronized with the extracted code text.

3. The method according to claim 1, characterized in that, The method includes: After completing the replacement of the code snippet of any branch to be synchronized, generate a corresponding code modification bill of lading and submit it to the code management platform.

4. The method according to claim 1, wherein The code synchronization configuration file includes multiple repository configuration items, and the repository configuration item includes a code configuration list, and the code configuration list includes at least one of the code configuration items.

5. A multi-branch code synchronization device, characterized in that, Including: A differential code acquisition module, configured to obtain the branch name in the code merge bill of lading and the differential code before and after modification when the code management platform receives a code merge bill of lading; A code snippet conversion module, configured to convert the differential code into a number of code snippet information; A configuration file acquisition module, configured to obtain a preset code synchronization configuration file, where the code synchronization configuration file includes at least one code configuration item, and the code configuration item includes a configuration item name, a branch name list, and a code snippet feature; A code snippet synchronization module, configured to traverse the code configuration items in the code synchronization configuration file. If any code configuration item matches any of the converted code snippet information, determine the branch to be synchronized according to the branch name and the branch name list of the any code configuration item, and synchronize the corresponding code text of the branch to be synchronized according to the any code snippet information.

6. The device according to claim 5, characterized in that The code snippet information includes a code snippet feature and the start and end line numbers of the code snippet, and the code snippet feature includes a code snippet type and a code snippet path; The code snippet synchronization module is configured to: Extract the corresponding code text from the code snippet information according to the code snippet path and the start and end line numbers of the code snippet in the code snippet information; and determine the code text to be synchronized in the branch to be synchronized according to the code snippet type and the code snippet path, and replace the code text to be synchronized with the extracted code text.

7. The device according to claim 5, characterized in that, The device further includes: After completing the replacement of the code snippet of any branch to be synchronized, a corresponding code change bill of lading is generated and submitted to the code management platform.

8. The device according to claim 5, characterized in that The code synchronization configuration file includes multiple repository configuration items, the repository configuration item includes a code configuration list, and the code configuration list includes at least one of the code configuration items.

9. A multi-branch code synchronization device, characterized in that, including: A communication interface for communicating with other electronic devices; A memory for storing computer program instructions; A processor for executing the computer program instructions to support the multi-branch code synchronization device to implement the method according to any one of claims 1 to 5.

10. A computer program product, characterized in that, including computer program instructions, the computer program instructions instruct the computer device to perform the operations corresponding to the method according to any one of claims 1 to 5.