Git study notes - cloned from a distal end of the branch management &

A, clones from the distal end

Creating SSH Key

See if there .ssh file again to see if there id.rsa and id.rsa.pub two files in the file.

Id.rsa which is private, id.rsa.pub is the public key

From a remote library clones

git clone

Two formats are supported:

SSH: //गीठ@गीठ.सनकुऐ.कॉम / ...

http://[email protected]/...

Second, the branch management

1, create and merge branches

Creating a branch Dev, Git creates a pointer dev, pointing to the master is the same price, then pointing dev HEAD, it means the current branch in the dev.

Dev branch now been revised and submitted, further, while the master dev pointer does not move forward before submission.

dev development is complete, we need to dev branch code and content into the master, then the master pointing dev current submission. To complete the merger.

In short: git merge is to change to change hands, work area remains unchanged.

Creating and merging branch instructions:

git checkout -b dev #创建Dev分支并切换到Dev分支

git checkout -b represents the creation and merger, the equivalent of two operations

git branch dev
git checkout dev  #切换分支
git merge dev 用于合并指定分支到当前分支

Remove excess branches

git branch -d dev

2, conflict resolution

Two branches of the same content the same level, the conflict will appear after submission. Schematic:

Git with <<<<<<<, =======, >>>>>>> different branches marked content, manually modified according to the modification of the contents of the file.

Need to manually resolve the conflict, and then re-price increases.

After submission can be viewed submitted by git log structure diagram

git log --graph

3, branch management strategy

(1) The combined git in two ways, one is the default git merge operation, wherein the parameter is a Fast-forward, the other is to add a parameter --no-ff.

The main difference:

1) Default merger

git merge

Reference two (1) combined in FIG.

2) combining the normal mode

Merger with parameters (nature: to create a branch, automatic submission (commit) it, and then merge)

git merge --no-ff -m"带参数的合并" dev

HEAD pointer on the same master.

(2) master version generally more stable, but to merge code, developed only on Dev.

image.png

合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并

4、bug分支

4.1)在修复bug时,工作区修改的内容还不想提交,此时,需要将工作区的内容进行临时保存。

git stash可以把当前的工作现场给“存储”起来,

$ git stash
Saved working directory and index state WIP on dev: f52c633 add merge

此时工作区就非常干净了,然后再用git status查看。

4.2)查看存储的“工作现场”

$ git stash list
stash@{0}: WIP on dev: f52c633 add merge

4.3)恢复工作现场

两种方式:

1)git stash apply 恢复

恢复后但不删除stash存储的内容,需要使用指令git stash drop 进行删除。

git stash apply

2)git stash pop 恢复

恢复后,同时删除stash存储的内容

5、分支强行删除

git branch -D <name>

6、多人协作

git push origin dev  #推送自己的分支
git pull #如果提交一次,需要将远端的分支拉取到本地(远端的分支信息比较自己的新)

如果使用git pull提示no tracing information 说明本地和远端没有建立连接,使用下面指令建立连接:

git branch --set-upstream-to dev origin/dev

附:查看远端的分支信息

git branch -v

7、Rebase

“曲线救国”

image.png

发布了327 篇原创文章 · 获赞 133 · 访问量 63万+

Guess you like

Origin blog.csdn.net/qq_30507287/article/details/85042494