2.git/gitlab重用指令

1.检出代码

git clone url 克隆远程项目,加 -b git_branch 指定分支

git clone http://github.app.xxx/wangyifan/hd_learn_pro.git 

2.初始化仓库

git init

3.查看分支

git branch

git branch # 查看本地分支
git branch -a # 查看远程分支,远程分支会显示为红色

《2.git/gitlab重用指令》 image.png

4.创建分支

git branch xxx

git branch wyf04   # 创建分支wyf04

《2.git/gitlab重用指令》 image.png

5.删除本地分支

git branch -d xxxxx

git branch -d wyf04  # 删除本地分支wyf04

《2.git/gitlab重用指令》 image.png

6.检出分支/分支切换

git checkout git_branch

git chekout wyf01 切换到wyf01分支

《2.git/gitlab重用指令》 image.png

7.把修改文件提交到缓冲区

git add

git add .

《2.git/gitlab重用指令》 image.png

8.本地提交

git commit -m “代码提交信息”

git commit -m '提交代码201904231002'

《2.git/gitlab重用指令》 image.png

9.推送代码

git pull origin

git push origin master  #将代码推送到远程主分支

《2.git/gitlab重用指令》 image.png

10.合并代码

git merge origin/remote

git merge origin/master  # 将本地当前分支与远程的master分支进行合并
git merge master  # 将本地当前分支与本地master分支进行合并

《2.git/gitlab重用指令》 image.png

11.拉取代码

git pull

git pull origin wyf01 # 拉取wyf01分支上的内容

《2.git/gitlab重用指令》 image

12.”挑拣”提交

git cherry-pick

# 分别提交三次修改
git log --oneline -3 查看当前分支最近三次的提交记录

《2.git/gitlab重用指令》 image.png

切换到其他分支,使用git cherry-pick命令,将第二次提交的内容合并到当前分支
当cherry-pick时,没有成功自动提交,这说明存在冲突,因此首先需要解决冲突,解决冲突后需要git commit手动进行提交

《2.git/gitlab重用指令》 image.png

或者git add .后直接使用git cherry-pick –continue继续。

《2.git/gitlab重用指令》 image.png

《2.git/gitlab重用指令》 合并冲突解决后.png

13.跟踪

git branch –set-upstream-to=remote_branch local_branch
本地分支与远程分支关联

《2.git/gitlab重用指令》 image.png

14.丢弃本地修改

git checkout — file # 撤销本地的修改

《2.git/gitlab重用指令》 image.png

《2.git/gitlab重用指令》 image.png

《2.git/gitlab重用指令》 image.png

《2.git/gitlab重用指令》 image.png

15.本地清除git上已经删除的分支

git remote prune origin
    原文作者:零_WYF
    原文地址: https://www.jianshu.com/p/04c8841ac00e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞