1.git分支

在前面我们基本了解Git的使用方法,这一节我们看下GIt重要概念【分支】

  1. 背景
  2. 例如于超老师在开发一个同性交友网站,刚写到登录功能,代码还没写完,今天先睡觉了,所以就commit提交到本地仓库了。
  3. 假如这会另一个程序员张三不知道,还直接对这个代码继续开发,这就乱套了。
  4. 讲道理,应该这么玩:
  5. 1. 分别给于超老师添加一个分支 yuchao,张三一个分支 zhangsan
  6. 2. 这俩人基于自己的分支环境去写代码,进行版本提交,却能互不影响
  7. 3. 最后将这2人的代码进行合并即可(需要考虑可能存在冲突,手动解决)

1.1 分支命令实践

默认版本仓库只有一个分支,master

  1. 查看当前我们在哪一个分支,有星星就是你在哪
  2. 此例的意思就是,我们有一个叫做 master 的分支,并且该分支是当前分支。
  3. 当你执行 git init 的时候,默认情况下 Git 就会为你创建 master 分支。
  4. 如果我们要手动创建一个分支。执行 git branch (branchname) 即可。
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch
  6. * master

创建分支

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch yuchao
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  3. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch
  4. * master
  5. yuchao

切换分支

  1. 1.进入到yuchao分支
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout yuchao
  3. Switched to branch 'yuchao'
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch
  5. master
  6. * yuchao

yuchao分支下写代码

这里就是公司里的多个程序员,如何开发同一套系统的流程了。

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#ls
  2. hello.sh laoliu.sh
  3. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#vim hello_world.sh
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git add .[root@www.yuchaoit.cn /home/yuchao/learn_git]#git commit -m 'yuchao 打印了一句话'
  6. [yuchao 164de7b] yuchao 打印了一句话 1 file changed, 1 insertion(+) create mode 100644 hello_world.sh[root@www.yuchaoit.cn /home/yuchao/learn_git]#[root@www.yuchaoit.cn /home/yuchao/learn_git]#lshello.sh hello_world.sh laoliu.sh[root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch master* yuchao[root@www.yuchaoit.cn /home/yuchao/learn_git]#git status# On branch yuchaonothing to commit, working directory clean

切换到master分支

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout master
  2. Switched to branch 'master'[root@www.yuchaoit.cn /home/yuchao/learn_git]#lshello.sh laoliu.sh[root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch
  3. * master
  4. yuchao

你此时只有切到yuchao分支,才能看到代码文件

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout yuchao
  2. Switched to branch 'yuchao'
  3. [root@www.yuchaoit.cn /home/yuchao/learn_git]#ls
  4. hello.sh hello_world.sh laoliu.sh

合并分支

合并yuchao分支的代码到master主干线上来

  1. 1.回到master主干分支
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout master
  3. Switched to branch 'master'
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git merge yuchao
  6. Updating 049a22f..164de7b
  7. Fast-forward
  8. hello_world.sh | 1 +
  9. 1 file changed, 1 insertion(+)
  10. create mode 100644 hello_world.sh
  11. [root@www.yuchaoit.cn /home/yuchao/learn_git]#ls
  12. hello.sh hello_world.sh laoliu.sh

分支冲突

这里是新添加了一个文件,合并数据还好,如果是同一个文件,且同一行数据的修改,岂不是GG?

1.再创建一个分支,zhangsan,搞破坏,且提交代码到版本仓库

  1. 创建且切换分支
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout -b zhangsan
  3. Switched to a new branch 'zhangsan'
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  6. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  7. [root@www.yuchaoit.cn /home/yuchao/learn_git]#echo "我是zhangsan,我就是来搞破坏的,你想咋地吧" >> laoliu.sh
  8. [root@www.yuchaoit.cn /home/yuchao/learn_git]#ls
  9. hello.sh hello_world.sh laoliu.sh
  10. [root@www.yuchaoit.cn /home/yuchao/learn_git]#cat laoliu.sh
  11. 加油啊兄弟们,胜利的曙光就要看到了!!
  12. 好的超哥,我一定相信自己,加油努力,给自己一个满意的结果!!
  13. 兄弟们,git工具,一般是开发人员用的多,我们运维一般也就是上传,下载代码而已了。
  14. 我是zhangsan,我就是来搞破坏的,你想咋地吧
  15. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git commit -m 'zhangsan 搞破坏'
  16. [zhangsan 8396a73] zhangsan 搞破坏
  17. 1 file changed, 1 insertion(+)
  18. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git log --oneline
  19. 8396a73 zhangsan 搞破坏
  20. 164de7b yuchao 打印了一句话
  21. 049a22f v1 hello.sh
  22. e9547df v3 就玩三次吧
  23. 9a3bd4d v2 添加了第二行数据
  24. fb118ba first commit with line 1

2.切换回master分支,别合并,先修改同一个文件,注意提交到版本仓库

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout master
  2. Switched to branch 'master'
  3. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#vim laoliu.sh
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  6. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  7. [root@www.yuchaoit.cn /home/yuchao/learn_git]#cat laoliu.sh -n
  8. 1 加油啊兄弟们,胜利的曙光就要看到了!!
  9. 2 好的超哥,我一定相信自己,加油努力,给自己一个满意的结果!!
  10. 3
  11. 4 兄弟们,git工具,一般是开发人员用的多,我们运维一般也就是上传,下载代码而已了。
  12. 5 兄弟们,我是master,我在第5行写了一句话
  13. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  14. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git add .
  15. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  16. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  17. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git commit -m 'master 也修改了laoliu.sh'
  18. [master 5be8816] master 也修改了laoliu.sh
  19. 1 file changed, 1 insertion(+)
  20. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  21. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git status
  22. # On branch master
  23. nothing to commit, working directory clean
  24. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git log --oneline -4
  25. 5be8816 master 也修改了laoliu.sh
  26. 164de7b yuchao 打印了一句话
  27. 049a22f v1 hello.sh
  28. e9547df v3 就玩三次吧

3.试试这回合并代码呢?master和zhangsan修改了同一行数据

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git merge zhangsan
  3. Auto-merging laoliu.sh
  4. CONFLICT (content): Merge conflict in laoliu.sh
  5. Automatic merge failed; fix conflicts and then commit the result.
  6. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  7. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  8. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git status
  9. # On branch master
  10. # You have unmerged paths.
  11. # (fix conflicts and run "git commit")
  12. #
  13. # Unmerged paths:
  14. # (use "git add <file>..." to mark resolution)
  15. #
  16. # both modified: laoliu.sh
  17. #
  18. no changes added to commit (use "git add" and/or "git commit -a")
  19. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  20. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  21. [root@www.yuchaoit.cn /home/yuchao/learn_git]#cat laoliu.sh
  22. 加油啊兄弟们,胜利的曙光就要看到了!!
  23. 好的超哥,我一定相信自己,加油努力,给自己一个满意的结果!!
  24. 兄弟们,git工具,一般是开发人员用的多,我们运维一般也就是上传,下载代码而已了。
  25. <<<<<<< HEAD
  26. 兄弟们,我是master,我在第5行写了一句话
  27. =======
  28. 我是zhangsan,我就是来搞破坏的,你想咋地吧
  29. >>>>>>> zhangsan

很明显,这里报错了,出现了冲突

4.手工解决冲突即可

  1. 这时候你作为技术老大,决定哪一行有用,哪一行没用,还是都保留。
  2. git使用`<<<<<<<<<,=========,>>>>>>>>`符号分割冲突的内容,手动删除这些符号,并修改成你想要的内容
  3. 修改结果如下
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#cat laoliu.sh
  5. 加油啊兄弟们,胜利的曙光就要看到了!!
  6. 好的超哥,我一定相信自己,加油努力,给自己一个满意的结果!!
  7. 兄弟们,git工具,一般是开发人员用的多,我们运维一般也就是上传,下载代码而已了。
  8. 兄弟们,我是master,我在第5行写了一句话
  9. 我是zhangsan,我就是来搞破坏的,你想咋地吧
  10. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  11. 提交新版本即可
  12. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git commit -m 'master fix both modified laoliu.sh'
  13. [master 07f7d81] master fix both modified laoliu.sh
  14. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git status
  15. # On branch master
  16. nothing to commit, working directory clean
  17. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  18. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  19. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git log --oneline -3
  20. 07f7d81 master fix both modified laoliu.sh
  21. 5be8816 master 也修改了laoliu.sh
  22. 8396a73 zhangsan 搞破坏

1.2 删除分支

  1. 注意不能删除当前分支
  2. 删除其他即可
  3. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git checkout master
  4. Already on 'master'
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  6. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch
  7. * master
  8. yuchao
  9. zhangsan
  10. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  11. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  12. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch -d yuchao zhangsan
  13. Deleted branch yuchao (was 164de7b).
  14. Deleted branch zhangsan (was 8396a73).
  15. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  16. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git branch
  17. * master

1.3 码云的分支

2.git标签

Git仓库内的数据发生变化时,我们经常会打上一个类似于软件版本的标签tag,这样通过标签就可以把版本库中的某个版本给记录下来,便于以后我们可以将特定的数据取出来。

2.1 为啥用git标签功能

git不是已经有commit了吗,可以附加提交信息,为什么还要tag呢?

开发小王:请吧上周一发布的版本打包发布,commit_id是3f6cccf0708525b58fe191c80325b73a54adee99

运维小于:你这什么乱七八糟的数字,,,太难找了,请你换个方法

开发小王换了个方式:请吧上周一发布的版本打包,版本号是v1.2,按照tag v1.2,查找commit 记录就行了!

所以tag就是一个容易记住的名字,和某个commit记录绑定在一起。

  1. 官网
  2. https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE
  3. 因此tagbranch一般会配合使用

2.2 tag标签实践

对当前提交的代码创建标签,-a标签名称,-m标签描述。

  1. 1. 对当前以存在的commit 进行打标签
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git log --oneline
  3. 07f7d81 master fix both modified laoliu.sh
  4. 5be8816 master 也修改了laoliu.sh
  5. 8396a73 zhangsan 搞破坏
  6. 164de7b yuchao 打印了一句话
  7. 049a22f v1 hello.sh
  8. e9547df v3 就玩三次吧
  9. 9a3bd4d v2 添加了第二行数据
  10. fb118ba first commit with line 1
  11. 2. 可以给当前最新的一个commit记录打标签
  12. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -a 'v1.0' -m '修复了支付功能'
  13. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  14. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  15. 3.查看tag列表
  16. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag
  17. v1.0
  18. 4.查看当前tag对应哪个commit
  19. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git show v1.0
  20. tag v1.0
  21. Tagger: pyyu <yc_uuu@163.com>
  22. Date: Thu Jul 7 17:48:30 2022 +0800
  23. 修复了支付功能
  24. commit 07f7d816bf052773c3f2ead1f3cc91299ede9e34
  25. Merge: 5be8816 8396a73
  26. Author: pyyu <yc_uuu@163.com>
  27. Date: Wed Jul 6 20:24:08 2022 +0800
  28. master fix both modified laoliu.sh
  29. diff --cc laoliu.sh
  30. index ca3bfc4,c0b43f0..77e26ae
  31. --- a/laoliu.sh
  32. +++ b/laoliu.sh
  33. @@@ -2,4 -2,4 +2,5 @@@
  34. 好的超哥,我一定相信自己,加油努力,给自己一个满意的结果!!
  35. 兄弟们,git工具,一般是开发人员用的多,我们运维一般也就是上传,下载代码而已了。
  36. +兄弟们,我是master,我在第5行写了一句话
  37. + 我是zhangsan,我就是来搞破坏的,你想咋地吧
  38. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  39. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git log --oneline
  40. 07f7d81 master fix both modified laoliu.sh
  41. 5be8816 master 也修改了laoliu.sh
  42. 8396a73 zhangsan 搞破坏
  43. 164de7b yuchao 打印了一句话
  44. 049a22f v1 hello.sh
  45. e9547df v3 就玩三次吧
  46. 9a3bd4d v2 添加了第二行数据
  47. fb118ba first commit with line 1
  48. 5.查看标签列表,有哪些标签
  49. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -l
  50. v1.0
  51. 6.给指定的commit记录,打上标签
  52. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -a 'v4' 8396a73 -m '张三你想干什么?'
  53. 7.查看tag且显示注释
  54. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -l -n
  55. v1.0 修复了支付功能
  56. v4 张三你想干什么?
  57. 8.删除tag
  58. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -d v4
  59. Deleted tag 'v4' (was 60cade7)
  60. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -d v1.0
  61. Deleted tag 'v1.0' (was 2da278c)
  62. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  63. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -l

3.git远程仓库

3.1 github

  1. 由于一堵墙,你可能是访问不了的,或者太慢

3.2 码云Gitee

  • git是一个分布式版本控制系统,同一个git仓库可以分布在不同的机器上,但是开发团队必须保证在同一个网络中,且必须有一个项目的原始版本,通常的办法就是让一台电脑充当服务器的角色,每天24小时开机,其他每个人都可以在这台"服务器"仓库里克隆一份代码到自己的电脑上。

  • 并且也可以把各自的代码提交到代码仓库里,也能从代码仓库拉取别人的提交。

  • 这样的代码仓库服务器,我们可以自由的搭建,也可以选择使用免费的托管平台。

  • Git代码托管平台,首先推荐的是Github,世界范围内的开发者都在使用Github托管代码,可以找到大量优秀的开源项目,缺点就是访问可能会卡一点。

  • 其次选择的就是Gitee,国内的代码托管平台,以及自建Gitlab服务器。

Gitee 提供免费的 Git 仓库,还集成了代码质量检测、项目演示等功能。

对于团队协作开发,Gitee 还提供了项目管理、代码托管、文档管理的服务。

官网地址

  1. https://gitee.com/

3.3 码云创建空仓库

创建完毕空仓库后,页面出现如下仓库使用方式,我们可以选择HTTPS和SSH两种协议和该仓库通信。

到这里,我们仓库就已经创建好了,接着就是要将本地客户端和服务端连接起来,存在于两种情况

  • 本地已经有一个git仓库了
  • 本地还没有git仓库

3.4 配置你的笔记本和码云仓库关联

以有了local repo(https需要输入账密)

采用https协议

  1. # 进入你自己的本地仓库,也就是有 .git的目录
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote add origin https://gitee.com/yuco/yuchaoit.git
  3. # 推送代码
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git push -u origin "master"
  5. Username for 'https://gitee.com': 877348180@qq.com
  6. Password for 'https://877348180@qq.com@gitee.com':
  7. Counting objects: 24, done.
  8. Compressing objects: 100% (20/20), done.
  9. Writing objects: 100% (24/24), 2.23 KiB | 0 bytes/s, done.
  10. Total 24 (delta 8), reused 0 (delta 0)
  11. remote: Powered by GITEE.COM [GNK-6.3]
  12. To https://gitee.com/yuco/yuchaoit.git
  13. * [new branch] master -> master
  14. Branch master set up to track remote branch master from origin.
  15. 3. 查看远程仓库的信息
  16. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote -v
  17. origin https://gitee.com/yuco/yuchaoit.git (fetch)
  18. origin https://gitee.com/yuco/yuchaoit.git (push)
  19. 4.删除远程仓库的地址信息,也就是断开你local repo 码云repo的关系了
  20. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote remove origin
  21. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  22. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote -v
  23. 5.重新设置即可
  24. git remote add origin https://gitee.com/yuco/yuchaoit.git

查看你推送上去的数据

3.5 配置ssh免密推送代码

  1. 可以直接访问地址
  2. https://gitee.com/profile/sshkeys

我们要在客户端生成key,结合gitee实现无密码登录,在linux和windows均可以使用ssh-keygen命令生成,需要注意的是在windows下只能生成rsa加密方式的key。

  1. ssh-keygen 一路回车到底即可
  2. [root@www.yuchaoit.cn /home/yuchao/learn_git]#cat ~/.ssh/id_rsa.pub

修改远程仓库的别名,改为git协议

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote -v
  2. origin https://gitee.com/yuco/yuchaoit.git (fetch)
  3. origin https://gitee.com/yuco/yuchaoit.git (push)
  4. 修改orgin别名的地址
  5. git@gitee.com:yuco/yuchaoit.git
  6. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote set-url origin git@gitee.com:yuco/yuchaoit.git
  7. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  8. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git remote -v
  9. origin git@gitee.com:yuco/yuchaoit.git (fetch)
  10. origin git@gitee.com:yuco/yuchaoit.git (push)

测试加点代码,加上tag,然后再推送试试

  1. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git status
  2. # On branch master
  3. nothing to commit, working directory clean
  4. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  5. [root@www.yuchaoit.cn /home/yuchao/learn_git]#ll
  6. total 12
  7. -rw-r--r-- 1 root root 33 Jul 6 20:07 hello.sh
  8. -rw-r--r-- 1 root root 53 Jul 6 20:14 hello_world.sh
  9. -rw-r--r-- 1 root root 384 Jul 6 20:23 laoliu.sh
  10. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  11. [root@www.yuchaoit.cn /home/yuchao/learn_git]#echo "你看这个灯,它又大又亮" > 吴亦凡^C
  12. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  13. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  14. [root@www.yuchaoit.cn /home/yuchao/learn_git]#echo '鸡你太美 嘿嘿嘿' > caixukun.log
  15. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git add .
  16. [root@www.yuchaoit.cn /home/yuchao/learn_git]#
  17. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git commit -m '两年半练习生来也'
  18. [master 37e1511] 两年半练习生来也
  19. 1 file changed, 1 insertion(+)
  20. create mode 100644 caixukun.log
  21. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git tag -a 'v1' -m '第一版菜徐琨'
  22. 推送数据
  23. [root@www.yuchaoit.cn /home/yuchao/learn_git]#git push origin master

3.6 克隆远程仓库

除了我们可以在本地创建目录,写代码,通过git管理版本,最后提交到远程仓库外,还有一种玩法。

也就是直接下载、克隆远程仓库中的源代码。

  1. 一种是直接克隆公开的源代码。
  2. 还有一种克隆私有的源代码,就需要账号密码验证了。

克隆公开仓库

  1. 克隆堡垒机jumpserver的源码
  2. [root@www.yuchaoit.cn /home/yuchao]#pwd
  3. /home/yuchao
  4. [root@www.yuchaoit.cn /home/yuchao]#ls
  5. learn_git
  6. [root@www.yuchaoit.cn /home/yuchao]#git clone git@gitee.com:fit2cloud-feizhiyun/Jumpserver.git
  7. Cloning into 'Jumpserver'...
  8. remote: Enumerating objects: 73544, done.
  9. remote: Counting objects: 100% (7202/7202), done.
  10. remote: Compressing objects: 100% (2866/2866), done.
  11. remote: Total 73544 (delta 4976), reused 6070 (delta 3979), pack-reused 66342
  12. Receiving objects: 100% (73544/73544), 63.46 MiB | 13.86 MiB/s, done.
  13. Resolving deltas: 100% (51447/51447), done.
  14. [root@www.yuchaoit.cn /home/yuchao]#ls
  15. Jumpserver learn_git
  16. [root@www.yuchaoit.cn /home/yuchao/Jumpserver]#git log --oneline -3
  17. 8ab4f6f docs: 添加 pr 提示说明
  18. 5a37540 docs: 修改贡献提示
  19. 1c1d507 Create CONTRIBUTING.md
  20. [root@www.yuchaoit.cn /home/yuchao/Jumpserver]#git remote -v
  21. origin git@gitee.com:fit2cloud-feizhiyun/Jumpserver.git (fetch)
  22. origin git@gitee.com:fit2cloud-feizhiyun/Jumpserver.git (push)

克隆自己公司的代码

  1. 1.运维小王克隆代码到本地
  2. git clone git@gitee.com:yuco/yuchaoit.git
  3. [root@www.yuchaoit.cn /home/xiaowang01]#git clone git@gitee.com:yuco/yuchaoit.git
  4. Cloning into 'yuchaoit'...
  5. remote: Enumerating objects: 27, done.
  6. remote: Counting objects: 100% (27/27), done.
  7. remote: Compressing objects: 100% (22/22), done.
  8. Receiving objects: 100% (27/27), done.
  9. remote: Total 27 (delta 9), reused 0 (delta 0), pack-reused 0
  10. Resolving deltas: 100% (9/9), done.
  11. [root@www.yuchaoit.cn /home/xiaowang01]#ls
  12. yuchaoit
  13. [root@www.yuchaoit.cn /home/xiaowang01]#cd yuchaoit/
  14. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#ls
  15. caixukun.log hello.sh hello_world.sh laoliu.sh
  16. 2. 创建分支,写代码
  17. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#git checkout -b xiaowang
  18. Switched to a new branch 'xiaowang'
  19. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#
  20. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#echo "我是小王,我写了点shell代码" > xiaowang.sh
  21. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#
  22. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#git add .
  23. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#
  24. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#git commit -m '小王写了个脚本'
  25. [xiaowang a801b50] 小王写了个脚本
  26. 1 file changed, 1 insertion(+)
  27. create mode 100644 xiaowang.sh
  28. 3.推送到代码仓库(xiaowang分支)
  29. [root@www.yuchaoit.cn /home/xiaowang01/yuchaoit]#git push -u origin xiaowang
  30. Counting objects: 4, done.
  31. Compressing objects: 100% (2/2), done.
  32. Writing objects: 100% (3/3), 334 bytes | 0 bytes/s, done.
  33. Total 3 (delta 1), reused 0 (delta 0)
  34. remote: Powered by GITEE.COM [GNK-6.3]
  35. remote: Create a pull request for 'xiaowang' on Gitee by visiting:
  36. remote: https://gitee.com/yuco/yuchaoit/pull/new/yuco:xiaowang...yuco:master
  37. To git@gitee.com:yuco/yuchaoit.git
  38. * [new branch] xiaowang -> xiaowang
  39. Branch xiaowang set up to track remote branch xiaowang from origin.

合并分支

1.网页端合并操作,创建合并的请求

2.审查提交请求

3.点击合并,且删除分支

4.完成合并,分支的代码就被合并到主干线了

git与gitee码云的更多相关文章

  1. git同步代码至github和gitee(码云)

    注:本文出自博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 本文源链接:https://www.cnblogs.com/chloneda/p/git-to-g ...

  2. 使用Git GUI工具 上传本地仓库到 gitee码云仓库

    前言: 网上关于git的命令操作与使用很多教程和博客,在使用git工具时我发现有一个 git Gui 可视化工具,我觉得十分的亲切,由于我之前一直是使用svn作为版本控制管理工具,都是可视化操作,使用 ...

  3. Ubuntu上Git的简单配置及使用(使用的代码托管平台为gitee码云)

    目录 1.关于gitee 2.Ubuntu下Git的下载及配置 3.使用Git连接到远程的Gitee仓库 4.常用命令 1.关于gitee Gitee(码云) 是 OSCHINA.NET 推出的代码托 ...

  4. 配置同时使用 Gitlab、Github、Gitee(码云) 共存的开发环境

    首先确认已安装Git,可以通过 git –version 命令可以查看当前安装的版本. Mac OSX 中都已经安装了Git.但是,Git的版本未必是最新的. 可以通过命令 git clone htt ...

  5. 使用Git Bash在码云上上传和下载代码

    前提是在码云上已经新建一个空的项目 1.新建一个目录,存放下载下来的项目,我在D盘新建了一个"gitspace"文件夹,用来存放下载下来的项目 2.进入刚刚新建的文件夹,即进入&q ...

  6. Git的使用--码云

    Git的使用--码云 进入码云官网:https://gitee.com/ 注册or登录账号进入gitee页面(页面结构大同小异). 点击右上角加号--新建仓库,用于存放项目代码 创建项目需要注意的选项 ...

  7. Git学习与码云实战

    Git学习与码云实战 一.Git安装 概述: Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理,是目前使用范围最广的版本管理工具. 下载安装: 下载地址:http ...

  8. 第一次Git使用以及码云(Gitee)

    下载安装Git,官网下载地址https://git-scm.com/downloads,我用的是Win10版,下载好后一路默认安装,安装时会给你自动添加环境变量,完成后打开cmd,输入git --ve ...

  9. Python集成开发环境Pycharm+Git+Gitee(码云)

    ********************************************************************* 本文主要介绍集成开发环境的配置过程,方便多人协作办公.代码版 ...

  10. git系列之---码云gitee 添加SHH公钥

    公钥 很多服务器都是需要认证的,SHH 认证是其中的一种:在客户端生成公钥,把生成的公钥添加到服务器,你以后连接服务器的时候就不用每次都输入用户名和密码了:很多git服务器都是用ssh认证方式,你需要 ...

随机推荐

  1. 【译】Visual Studio Enterprise 中的代码覆盖率特性

    通过使用代码覆盖率功能,您可以发现您的测试需要改进的地方,并使您的软件更加健壮和可靠.在这篇文章中,我们将介绍我们在 Visual Studio Enterprise 2022 中引入的 Code C ...

  2. Android Native crash 处理案例分享

    简介: Android Native crash 处理案例分享 1. 背景 目前 mPaas[1] Android使用Crash SDK对闪退进行的处理,CrashSDK 是 Android 平台上一 ...

  3. WPF 动画实战 点击时显示圆圈淡出效果

    本文告诉大家一个有趣的动画,在鼠标点击的时候,在点击所在的点显示一个圆圈,然后这个圆圈做动画变大,但是颜色变淡的效果.本文的控件可以让大家将对应的容器放在自己应用里面就能实现这个效果 这个效果特别简单 ...

  4. vue+vant+js实现购物车原理小demo(中级版有选择)

    增加只计算已选的的购物车商品功能.效果图: main.js: Vue.use(Stepper); Vue.use(Checkbox); Vue.use(CheckboxGroup); 上代码: < ...

  5. 如何用python运用ocr技术来识别文字

    要先安装ocr技术,也就是光学符号识别,通过扫描等光学输入方式将各种票据.报刊.书籍.文稿及其他印刷品的文字转化为图像信息,再利用文字识别技术将图像信息转化为可以使用的文本的技术(我在百度百科抄的), ...

  6. 01. Linux 如何安装rvm和ruby

    参考: https://blog.csdn.net/qq_35641923/article/details/86493822 https://www.runoob.com/ruby/ruby-inst ...

  7. Golang、python中MD5、SHA512、base64编码等

    在GO中处理的话,比较方便. func main() { fmt.Println(md5Str("woGo")) fmt.Println(sha512Str("woGo& ...

  8. 在tomcat上安装PFX格式证书部署https

    您可以在Tomcat服务器安装已签发的SSL证书,实现通过HTTPS安全访问Web服务.本文介绍如何在Tomcat服务器安装PFX格式的SSL证书. 步骤一:在阿里云的域名管理后台,下载SSL证书 登 ...

  9. Vue+springboot集成PageOffice实现在线编辑Word、excel文档

    说明: PageOffice是一款在线的office编辑软件,帮助Web应用系统或Web网站实现用户在线编辑Word.Excel.PowerPoint文档.可以完美实现在线公文流转,领导批阅,盖章.可 ...

  10. kubernetes 之Health Check 健康检查

    默认的健康检查 这里Pod的restartPolicy设置为OnFailure,默认为Always. [machangwei@mcwk8s-master ~]$ cat mcwHealthcheck. ...