git合并代码操作-2022新项目(Git merge code operation-2022 new project)

  自己做开发工作已经好几年,以前由于都是开发一些小项目,基本上也没拉什么分支进行开发,也没有涉及到合并代码的操作,因此自己对于如何合并代码还真没有实际地操作过。今天负责人突然交给我一个任务,让我去合并代码,将他在分支上写的代码合并到我开发的这个分支上来。首先说说目前项目中代码仓库的情况,有一个 master 主干,负责人先创建了一个分支A进行开发,

之后我使用分支A又拉取了一个分支B进行开发。拿到这个任务后,我首先想到的就是使用搜索引擎来学习,查找自己需要掌握的技能。

公司内网不能使用google,只能使用必应搜索: git合并代码 很快出来很多的博文、教程。反正自己不知道该怎么合并,就一个一个的进行尝试呗。

尝试方式一:进入到B分支中进行操作 。这种合并的方式是直接合并两个分支的所有代码 git merge 分支名,可以参考下面的文章。测试结果git 报错。https://www.cnblogs.com/linjiqin/p/7756164.html

尝试方式二:  由于是内网开发,禁止截图、禁止拍照、禁止将任何与开发相关的信息上传到网上,只能访问部分网站比如博客园,CSDN等等。所以对于问题的解决过程,只能够通过文字描述。这种方式的思路和第一种方式有所区别。主要是先获取需要被合并代码如B分支的提交日志信息,然后在根据日志信息来进行合并。可以合并一条提交记录,也可以合并多条不连续的提交记录,或者合并多条连续的提交记录。自己按照教程的操作,先找出从开始日期起,每条提交记录的ID,然后把它放到一个文件中整理好之后在进行使用。   自己一次性选择了9条提交信息,执行完后去IDEA中查看代码是否合并成功,发现有java文件变红了,打开一看里面有很多报错的地方。

我猜这就是需要我进行合并的地方。开始时是一个一个地修改里面有错误的地方,可是发现太多了,这样改不是办法。然后又继续看了一些博文,

大致处理方式为需要自己手动解决有冲突的文件,然后才能够提交合并后的代码。方式为可以使用直接使用IDEA点击提交按钮,

这时并不是真正的提交代码,而是可以将有冲突的文件都找出来,然后在一个文件一个文件的进行处理。一般都是选中文件,右键选择处理冲突,

要么使用自己的代码来覆盖当前冲突的文件,要么使用其他人的代码来覆盖当前的冲突文件。自己毫不犹豫地选择后者,

冲突解决后,先编译一下,发现还有问题,说是类未找到。这时自己才发现git提交ID的先后顺序颠倒过来了,

所以导致出现错误。自己把报错信息放搜索引擎里面搜索, 知道可以放弃合并的代码,让代码恢复到合并之前的状态。

立马执行,然后重新执行合并命令,同时合并9条提交记录,这时候再去看代码发现一切正常。参考博文如下:https://www.cnblogs.com/liuminxiu0707/p/14778428.html

————————

I have been doing development work for several years. In the past, I developed some small projects, basically did not pull any branches for development, and did not involve the operation of merging code. Therefore, I really didn’t actually operate on how to merge code. Today, the person in charge suddenly gave me a task to merge the code he wrote on the branch into the branch I developed. First, let’s talk about the current situation of the code warehouse in the project. There is a master backbone. The person in charge first created a branch a for development,

Then I used branch a to pull another branch B for development. After getting this task, my first thought is to use search engine to learn and find the skills I need to master.

Google can’t be used in the company’s intranet, only Bing search can be used: git merge code will soon produce a lot of blog posts and tutorials. Anyway, I don’t know how to merge, so I’ll try one by one.

Try method 1: enter branch B for operation. This merging method is to directly merge all code git merge branch names of the two branches. You can refer to the following article. The test result git reports an error. https://www.cnblogs.com/linjiqin/p/7756164.html

Try 2: because it is an intranet development, screenshots, photos and uploading any development related information to the Internet are prohibited. You can only visit some websites, such as blog Garden, CSDN and so on. Therefore, the problem-solving process can only be described in words. This way of thinking is different from the first way. It is mainly to obtain the submission log information of the code to be merged, such as branch B, and then merge according to the log information. You can merge one submission record, multiple discontinuous submission records, or multiple continuous submission records. According to the operation of the tutorial, first find out the ID of each submission record from the start date, and then put it into a file to sort it out before use. I selected 9 pieces of submission information at one time. After execution, I went to the idea to check whether the code was merged successfully. I found that some java files turned red. I opened them to see that there were many error reports.

I guess that’s where I need to merge. At the beginning, I revised the mistakes one by one, but I found too many. This is not the way. Then I continued to read some blogs,

The general handling method is to manually resolve the conflicting files before submitting the merged code. You can directly use idea and click the submit button,

At this time, the code is not really submitted, but the conflicting files can be found and processed one by one. Generally, you select a file and right-click to select handle conflict,

Either use your own code to overwrite the current conflicting file, or use someone else’s code to overwrite the current conflicting file. I chose the latter without hesitation,

After the conflict is resolved, compile it first. It is found that there are still problems. It is said that the class is not found. At this time, I found that the order of GIT submitting ID was reversed,

This causes an error. Put the error information into the search engine and know that you can give up the merged code and restore the code to the state before merging.

Execute it immediately, then re execute the merge command, merge 9 submission records at the same time, and then look at the code and find that everything is normal. Reference blog posts are as follows: https://www.cnblogs.com/liuminxiu0707/p/14778428.html