五、Git-本地命令行

1.Git介绍

Git是一种分布式版本控制系统的实现,客户端并不只是提取最新版本的文件快照,而是把代码仓库完整的镜像下来,包括了完整的历史记录.

五、Git-本地命令行_第1张图片

2.Git 命令行

2.1.安装

https://git-scm.com/download/win
64-bit Git for Windows Setup
下载完成之后,选择安装路径,其他的选项参照下图:
五、Git-本地命令行_第2张图片
五、Git-本地命令行_第3张图片
五、Git-本地命令行_第4张图片

2.2.本地化操作

2.2.1.配置sshkey,实现免密提交

在git bash里执行 ssh-keygen -t rsa -C "a[email protected]m",可以不输入密码
在git bash里执行 cd ~/.ssh
在git bash里执行vim id_rsa.pub,将里面的内容复制到 gitlab -> 右上角 ->edit profile -> SSH KEYS -> add key

2.2.2.配置提交人、邮箱

git config --global user.name "abc"
git config --global user.email "a[email protected]m"
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" # 配置日志格式
git config --list

2.2.3初始化本地代码库

git init

2.2.4.本地添加及提交

git add . -A # 将代码从workspace 添加到 stash(index)
git commit -m "feat:实现Hello DevOps DEVOPS-15" # 将代码从stash(index) 添加到repository

2.2.5.查看日志

git log
git lg

2.2.6.查看状态

git status

2.2.7.本地撤销

git commit -amend # 用新的提交覆盖上一次提交,避免“笔误,修正小错误”等信息覆盖有效的提交日志信息
git reset head # 从stash(index) 撤销添加
git reset --soft head^ # 撤销到上一个版本
git reset --soft head~2 # 撤销前2次提交
git revert 12345678 # 撤销 12345678提交

2.2.8.创建分支

git checkout -b branch_name

2.2.9.查看分支

git branch -a

2.2.10.切换分支

git checkout branch_name

2.2.11.删除分支

git branch -d branch_name # 不能删除当前的分支,在删除分支前进行分支的切换

2.2.12.合并分支

git merge branch_name # 将branch_name 合并到当前分支

2.2.13.合并分支并解决冲突

git merge branch_name # 将branch_name合并到当前分支
git status # 查看冲突的文件
vi conflict_file # <<<<<<< ===========>>>>>>>>>>> 解决这里的冲突问题
git add . -A && git commit -m "feat:message ISSUE-KEY" # 提交解决后的问题,在合并的分支上操作 ,合并的分支会提示"branch_name | merging"

你可能感兴趣的:(git)