Git 实战(三) | Github 必会高频基础命令与 IDE 的 Git 集成(Git actual combat (3) | GitHub must be able to integrate high-frequency basic commands with git of IDE)

本文是 Git 实战系列第 3
篇,作者月关,霍格沃兹测试学院优秀学员。一个在质量保障领域攀登探索的tester,致力于用技术改变身边人对测试的认识。对Web,接口和APP
自动化均有所涉及。

本文是 Git 实战系列第 3
篇,作者月关,霍格沃兹测试学院优秀学员。一个在质量保障领域攀登探索的tester,致力于用技术改变身边人对测试的认识。对Web,接口和APP
自动化均有所涉及。

** 1.Fork**

GitHub 上我们可以 fork
别人的项目,为了与别人产生一种协作关系,将他人的项目在自己本地创建也一个,这里以霍格沃兹测试学院(Hogwarts)的演练环境做演示:

1.1) 点击fork按钮对项目进行fork:

1.2)fork完成后就可以在我们自己的GitHub账户下见到被fork的项目:

** 2.Clone**

2.1)接着我们使用命令将fork的项目clone到本地:

git clone

这个时候可以将此项目看做是自己的一个项目,可以任意修改;

2.2)项目的作者可以看到有哪些人fork了自己的项目:

** 3.Push**

3.1) 先在本地修改README.md文件为:

# Hogwarts_Online2  
霍格沃兹测试学院定向班第二期演练try it

3.2)将文件提交到本地仓库:

这个时候可以看到提交的作者已经变成我们自己了;
也可以使用git remote -v命令来查看,可见现在本地仓库与远程仓库直接关联的是fork之后的项目:

3.3)只用git push命令将本地仓库的文件推到远程仓库中去:

如下图可以看到已经成功将修改后的README.md文件推到了GitHub上:

** 4.PR(pull request)**

pr:全称 pull request,当我们修改了 fork 后的项目后,因为不能直接修改别人的项目,这个时候想要将自己的修改与原项目合并,就可以使用 pr
来向原项目作者进行申请

4.1)发起 pr,点击 New pull request:

然后我们可以看到仓库路径从我的仓库向原作者项目仓库地址发起 pr 请求,在下面可以看到我对项目的修改 diff:

4.2)这个时候我们点击按钮,填写描述后再点击按钮:

Create new pull request
Create new pull request

** 5.merge PR**

这个时候原仓库维护人员就可以收到pr,并对其进行审核、评论、merge或close的操作:

5.1) 在文件修改没有冲突(conflict)的时候,可以直接merge:

5.2) 当文件修改有冲突的时候,就需要原作者去进行RResolve了:

5.3) 或者有冲突的pr直接close:

总结下来有以下三种情况:

  • 无冲突直接merge
  • 有冲突手工merge
  • 有冲突close并重新发起pr

** 6.Fetch(实际使用的相对较少,更多的使用remote)**

有时候我们fork了项目,但是很有可能我们对项目的修改会比原项目滞后,这就会导致pr的时候容易出现conflict;为了能让我们知道当前的修改是否conflict,就需要使用git
fetch命令了;

使用 git fetch 拿下来一个远程分支的文件,看一下这个分支和我自己的有什么冲突。

** 7.Remote**

7.1)先使用git remote -v命令来查看本地仓库与远程仓库的关联关系

这个时候我们可以增加一个,选择原仓库的地址,使用命令来添加一个:

remote
HTTPS
git remote add <远端名> <远端地址>
remote

7.2)再将远程端的master分支fetch到本地:

7.3) 这时候使用git merge将当前master分支与远端分支合并:

结果中我们发现产生了冲突,再使用命令查看:

git status

发现两边都修改了,这个时候我们使用对进行查看,当我们的时候,系统会把文件换成以下的展示模式:

README.md
vi
README.md
merge

这种展示模式的意思是以等号=为分隔符,等号上方为当前分支的修改,等号下方为远程分支的修改,这样就产生的冲突,我们可以手动进行修改,然后merge:

7.4) 这个时候刷新GitHub,在我们自己的分支仓库中可以看到已经成功将修改进行:

merge

这个时候如果再进行的话,遇见的几率就会小的多了
命令简单总结: __

pr
conflict
git remote add other xxxx git fetch other mastergit merge remotes/other/maste

到这里,一个基本的git分支管理的流程就走完了,再简单介绍一下IDE中的Git集成 __

** 8.IDE中的Git集成**

8.1)将项目用IDEA打开,在中可以看到我们的提交管理线:

Version Control -> log

8.2)双击文件可以查看文件diff:

8.3)在右下角还可以进行Git分支的管理:

**
来霍格沃兹测试开发学社,学习更多软件测试与测试开发的进阶技术,知识点涵盖web自动化测试 app自动化测试、接口自动化测试、测试框架、性能测试、安全测试、持续集成/持续交付/DevOps,测试左移、测试右移、精准测试、测试平台开发、测试管理等内容,课程技术涵盖bash、pytest、junit、selenium、appium、postman、requests、httprunner、jmeter、jenkins、docker、k8s、elk、sonarqube、jacoco、jvm-sandbox等相关技术,全面提升测试开发工程师的技术实力
QQ交流群:484590337
公众号 TestingStudio
点击获取更多信息

————————

This article is the third in Git’s actual combat series
The author, yueguan, is an outstanding student of Hogwarts Testing Institute. A tester climbing and exploring in the field of quality assurance is committed to changing people’s understanding of testing with technology. For web, interface and app
Automation is involved.

This article is the third in Git’s actual combat series
The author, yueguan, is an outstanding student of Hogwarts Testing Institute. A tester climbing and exploring in the field of quality assurance is committed to changing people’s understanding of testing with technology. For web, interface and app
Automation is involved.

** 1. Fork**

We can fork on GitHub
For other people’s projects, in order to create a collaborative relationship with others, create another one locally. Here, take the exercise environment of Hogwarts test institute as a demonstration:

1.1) click the fork button to fork the project:

1.2) after the fork is completed, we can see the forked projects under our own GitHub account:

** 2. Clone**

2.1) next, we use the command to clone the fork project locally:

git clone

At this time, you can regard this project as your own project, which can be modified at will;

2.2) the author of the project can see who forked their own project:

** 3. Push**

3.1) modify readme locally first The MD file is:

# Hogwarts_Online2  
霍格沃兹测试学院定向班第二期演练try it

3.2) submit documents to local warehouse:

At this time, we can see that the author submitted has become ourselves;
You can also use the GIT remote – V command to view. It can be seen that the projects after fork are directly associated with the local warehouse and the remote warehouse:

3.3) only use git push command to push files from local warehouse to remote warehouse:

As shown in the figure below, you can see that the modified readme has been successfully MD file pushed to GitHub:

** 4.PR(pull request)**

PR: the full name of pull request. When we modify a forked project, we can’t directly modify others’ projects. At this time, if we want to merge our own modifications with the original project, we can use pr
To apply to the original project author

4.1) initiate PR and click new pull request:

Then we can see that the warehouse Path initiates PR request from my warehouse to the warehouse address of the original author’s project. Below, we can see my modification diff to the project:

4.2) at this time, we click the button, fill in the description, and then click the button:

Create new pull request
Create new pull request

** 5.merge PR**

At this time, the original warehouse maintenance personnel can receive PR and review, comment, merge or close it:

5.1) when there is no conflict in file modification, you can merge directly:

5.2) in case of conflict in document modification, the original author is required to rresolve:

5.3) or PR direct close in conflict:

To sum up, there are three situations:

  • Conflict free direct merge
  • Conflicting manual merge
  • Close and re initiate PR in case of conflict

** 6. Fetch (relatively few are actually used, and more are remote)**

Sometimes we fork the project, but it is likely that our modifications to the project will lag behind the original project, which will lead to conflict in PR; In order to let us know whether the current modification is conflicting, we need to use GIT
Fetch command;

Use git fetch to take down the file of a remote branch and see if this branch conflicts with my own.

** 7.Remote**

7.1) first use the GIT remote – V command to view the association relationship between the local warehouse and the remote warehouse

At this time, we can add one. Select the address of the original warehouse and use the command to add one:

remote
HTTPS
git remote add <远端名> <远端地址>
remote

7.2) fetch the master branch at the remote end to the local:

7.3) at this time, use git merge to merge the current master branch with the remote branch:

As a result, we found a conflict, and then use the command to view:

git status

It is found that both sides have been modified. At this time, we use the to view. When we, the system will change the file to the following display mode:

README.md
vi
README.md
merge

This display mode means that the equal sign = is used as the separator, the modification of the current branch is above the equal sign, and the modification of the remote branch is below the equal sign. In this way, we can modify the conflicts manually, and then merge:

7.4) refresh GitHub at this time, and you can see in our own branch warehouse that the modification has been successfully made:

merge

If we do it again at this time, the probability of meeting will be much smaller
Command summary:__

pr
conflict
git remote add other xxxx git fetch other mastergit merge remotes/other/maste

Here, a basic git branch management process is finished. Let’s briefly introduce git integration in the IDE__

** 8. Git integration in IDE**

8.1) open the project in idea, where you can see our submission management line:

Version Control -> log

8.2) double click the file to view the file diff:

8.3) git branch management can also be performed in the lower right corner:

**
Come to Hogwarts test and development society to learn more advanced technologies of software testing and test development. The knowledge points include web automated testing, APP automated testing, interface automated testing, test framework, performance testing, security testing, continuous integration / continuous delivery / Devops, test left, test right, precision testing, test platform development, test management, etc, The course technology covers bash, pytest, JUnit, selenium, appium, postman, requests, httprunner, JMeter, Jenkins, docker, k8s, elk, sonarqube, Jacobo, JVM sandbox and other related technologies, so as to comprehensively improve the technical strength of test and development engineers
QQ communication group: 484590337
The official account TestingStudio
Click for more information