Search

CN-120848855-B - Code branch switching method, device, equipment and storage medium

CN120848855BCN 120848855 BCN120848855 BCN 120848855BCN-120848855-B

Abstract

The application discloses a code branch switching method, a device, equipment and a storage medium, wherein the method comprises the following steps: and responding to a code copy switching instruction of the target branch, traversing all copies of the code warehouse, judging whether the copies are in the target branch, if not, switching the current branch to the target branch when the current branch meets a first condition and the far end of the code warehouse meets a second condition, wherein the first condition is that no uncommitted or unpivoted code exists in a working area of the current branch, the second condition is that all code commit records of the current branch are contained in the far end, and switching the current branch to a preset default branch if the target branch does not exist in the far end. Therefore, when the branches need to be switched, the method automatically judges how to switch the branches, prevents a developer from switching the branches under the condition of not submitting codes, reduces manual operation errors of the developer, and improves development accuracy.

Inventors

  • CAO GAOYANG
  • HONG QINGQIN
  • Huang Lvqi
  • MA LIKE
  • WANG ZIJUN

Assignees

  • 广州鼎甲计算机科技有限公司

Dates

Publication Date
20260508
Application Date
20250728

Claims (10)

  1. 1. A code finger switching method, comprising: Responding to a code copy switching instruction of a target branch, traversing all copies of a code warehouse, and judging whether the copies are positioned in the target branch or not; if not, when the current branch meets a first condition and the far end of the code warehouse meets a second condition, if the target branch exists at the far end, switching the current branch to the target branch, wherein the first condition is that no uncommitted or unpived code exists in a working area of the current branch, and the second condition is that all code commit records of the current branch are contained at the far end; and if the target branch does not exist at the far end, switching the current branch to a preset default branch.
  2. 2. The method as recited in claim 1, further comprising: If the current branch does not meet the first condition or the far end does not meet the second condition, creating a new copy, and switching a current working directory to a directory of the new copy; judging whether the branch of the new copy exists at the far end; if yes, switching the current branch to the target branch; if not, switching the current branch to the preset default branch.
  3. 3. The method of claim 2, wherein the creating a new copy comprises: Creating an empty item copy; copying the work codes under the current work directory to the project copy; And clearing an intermediate product generated by the working code in the process of copying to the project copy under the directory of the project copy to obtain a new copy.
  4. 4. A method according to claim 3, wherein said creating an empty copy of an item comprises: Traversing all existing item copies, and determining the maximum value naming of all item copies; And creating an empty item copy according to the maximum value naming.
  5. 5. The method of any one of claims 1-4, further comprising: and if the target copy is in the target branch, switching the current working directory to the directory of the target copy.
  6. 6. A code finger switching device, comprising: The target branch copy judging unit is used for responding to a code copy switching instruction of a target branch, traversing all copies of the code warehouse, judging whether the copies are positioned on the target branch or not, and executing the target branch switching unit if the copies are not positioned on the target branch; A first target branch switching unit, configured to switch a current branch to a target branch if the target branch exists at a far end when the current branch meets a first condition and the far end of the code warehouse meets a second condition, where the first condition is that no uncommitted or unpivoted code exists in a working area of the current branch, and the second condition is that the far end includes all code commit records of the current branch; And the first default branch switching unit is used for switching the current branch to a preset default branch if the target branch does not exist at the far end.
  7. 7. The apparatus as recited in claim 6, further comprising: A new copy creation unit, configured to create a new copy if the current branch does not satisfy the first condition or the far-end does not satisfy the second condition, and switch a current working directory to a directory of the new copy; A remote branch existence judging unit, configured to judge whether a branch where the new copy exists at the remote end, if yes, execute a second target branch switching unit, and if no, execute a second default branch switching unit; The second target branch switching unit is used for switching the current branch to the target branch; the second default branch switching unit is configured to switch the current branch to the preset default branch.
  8. 8. The apparatus of claim 7, wherein the new copy creation unit comprises: An empty copy creation unit, configured to create an empty item copy if the current branch does not satisfy the first condition or the far-end does not satisfy the second condition; the code copying unit is used for copying the working codes under the current working directory to the project copy; And the intermediate product clearing unit is used for clearing the intermediate product generated in the process of copying the work code to the project copy under the directory of the project copy to obtain a new copy.
  9. 9. A code branch switching device comprising a memory and a processor; the memory is used for storing programs; The processor is configured to execute the program to implement the steps of the code branch switching method according to any one of claims 1 to 5.
  10. 10. A storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the code branch switching method as claimed in any one of claims 1-5.

Description

Code branch switching method, device, equipment and storage medium Technical Field The present application relates to the field of software development technologies, and in particular, to a method, an apparatus, a device, and a storage medium for switching code branches. Background In software development, git is used as a mainstream distributed version control system, and branch management is supported, but limitation exists in a multi-task parallel development scene. Often, a developer needs to maintain multiple warehouse copies to avoid intermediate product interference during branch switching, but needs to manually manage copy synchronization and switching, and version confusion is easily caused by misoperation. Meanwhile, if the uncommitted change exists before the branch is switched, the function is easy to be lost due to missing submission, and the error risk is greatly increased. Therefore, how to realize automatic code branch switching so as to reduce manual misoperation and improve development accuracy is a problem needing attention. Disclosure of Invention In view of the above problems, the present application provides a method, an apparatus, a device, and a storage medium for switching code branches, so as to reduce manual operation errors and improve development accuracy. In order to achieve the above object, the following specific solutions are proposed: a code branch switching method, comprising: Responding to a code copy switching instruction of a target branch, traversing all copies of a code warehouse, and judging whether the copies are positioned in the target branch or not; if not, when the current branch meets a first condition and the far end of the code warehouse meets a second condition, if the target branch exists at the far end, switching the current branch to the target branch, wherein the first condition is that no uncommitted or unpived code exists in a working area of the current branch, and the second condition is that all code commit records of the current branch are contained at the far end; and if the target branch does not exist at the far end, switching the current branch to a preset default branch. Optionally, the method further comprises: If the current branch does not meet the first condition or the far end does not meet the second condition, creating a new copy, and switching a current working directory to a directory of the new copy; judging whether the branch of the new copy exists at the far end; if yes, switching the current branch to the target branch; if not, switching the current branch to the preset default branch. Optionally, the creating the new copy includes: Creating an empty item copy; copying the work codes under the current work directory to the project copy; And clearing an intermediate product generated by the working code in the process of copying to the project copy under the directory of the project copy to obtain a new copy. Optionally, the creating an empty item copy includes: Traversing all existing item copies, and determining the maximum value naming of all item copies; And creating an empty item copy according to the maximum value naming. Optionally, the method further comprises: and if the target copy is in the target branch, switching the current working directory to the directory of the target copy. A code finger switching device comprising: The target branch copy judging unit is used for responding to a code copy switching instruction of a target branch, traversing all copies of the code warehouse, judging whether the copies are positioned on the target branch or not, and executing the target branch switching unit if the copies are not positioned on the target branch; A first target branch switching unit, configured to switch a current branch to a target branch if the target branch exists at a far end when the current branch meets a first condition and the far end of the code warehouse meets a second condition, where the first condition is that no uncommitted or unpivoted code exists in a working area of the current branch, and the second condition is that the far end includes all code commit records of the current branch; And the first default branch switching unit is used for switching the current branch to a preset default branch if the target branch does not exist at the far end. Optionally, the apparatus further comprises: A new copy creation unit, configured to create a new copy if the current branch does not satisfy the first condition or the far-end does not satisfy the second condition, and switch a current working directory to a directory of the new copy; A remote branch existence judging unit, configured to judge whether a branch where the new copy exists at the remote end, if yes, execute a second target branch switching unit, and if no, execute a second default branch switching unit; The second target branch switching unit is used for switching the current branch to the target branch; the second default branch switching unit