Git rename remote branch | Irregular operation, two lines of tears for relatives.

Continue to create, accelerate growth! This is the 8th day of my participation in the "Nuggets Daily New Plan · June Update Challenge", click to view the details of the event

TIPS: The following code example language is Go

Problem Description

Xiao A and I are developing in parallel, he is optimizing the code logic before, and I am developing new functions.

Xiao A submitted the code to the test branch before me, and I found a lot of conflicts when I wanted to submit my new function code to the test branch.

Resolving conflicts first is a waste of time, and my new feature code needs to resolve conflicts every time it is proposed.

In addition, when I test the branch to resolve the conflict, I can only solve it according to the code logic optimized by Xiao A, which is not consistent with my own branch logic.

The code delivered to the test classmates is inconsistent with the code of my own branch. This kind of test is meaningless.

Reflect on what went wrong

  1. Unreasonable use of factory mode

  2. Unreasonable assignment of tasks

code level

Because it is the factory design pattern, the implementation class A I am responsible for is not directly related to its implementation class B. But because he modified the method definition in the factory class.

For example, the interface in the previous factory class is defined like this

package factory

type xxx interface {
   GetXxxx(ctx context.Context, req aaa.aa) (res bbb.bb, err error)  
}
复制代码

But Xiao A modified the interface definition in the factory class:

package factory

type xxx interface {
   GetXxxx(ctx context.Context, req ccc.cc) (res ddd.dd, err error)  
}
复制代码

This leads to a problem:

If I want to merge my code into the test branch, I also have to modify the parameter type and return type of my implementation class A.

But we are all developing on different branches, and I don't have the type defined by ccc.cchim ddd.dd.

I can't define him directly ccc.cc. ddd.ddI want to come over and develop on my own branch. First, because of inconsistent requirements, the online cycle of Xiao A will be longer than mine. Second, this operation itself is not standardized.

Solve the problem

Optimize from code design:

The solution we think of is to use the interface reasonably

Set the input and output parameters of the interface method to be implemented in the factory class to the interface{}type

package factory

type xxx interface {
   GetXxxx(ctx context.Context, req interface{}) (res interface{}, err error)  
}
复制代码

This makes it easier to expand.

Optimized from git operations:

But the method of setting the input and output parameters as interface{}types did not fundamentally solve our problem.

The reason is this:

The requirement of small A is to optimize the input and output parameters of the factory class and each implementation class as a whole, optimize the internal logic, and extract methods.

The modification of small A leads to a big conflict with my implementation logic.

But his git submission was submitted to the test environment before me, so I couldn't submit my code. If I wanted to submit, I had to resolve various conflicts. To resolve the conflict, we must change it according to the optimization logic of Xiao A, and the tests given to the test students are inconsistent with my own branch.

Hard to top.

Considering that the modification of small A does not need to be tested for the time being, the online cycle is also relatively long.

The final solution is this:

Pulled a backup branch from the remote test branch

delete the remote test branch

Submit the branch I need to test locally to the test branch and deliver the test.

git rename remote branch

1. Rename the local branch first

git branch -m 旧分支名称  新分支名称
复制代码

2. Delete the remote branch

git push --delete origin 旧分支名称
复制代码

3. Upload the local branch with the new modified name

git push origin 新分支名称
复制代码

4. The modified local branch is associated with the remote branch

git branch --set-upstream-to origin/新分支名称
复制代码

Summarize

It's cool to develop and maintain a crematorium.

The operation is not standardized, and the relatives are in tears.

at last

Thank you for reading, and welcome everyone: like, favorite,coin(focus on)! ! !

8e95dac1fd0b2b1ff51c08757667c47a.gif

Guess you like

Origin juejin.im/post/7104258964732575775