五、Git-本地命令行

大神丸子 -
五、Git-本地命令行
1.Git介绍

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

image.png

2.Git 命令行2.1.安装

https://git-scm.com/download/win
64-bit Git for Windows Setup
下载完成之后,选择安装路径,其他的选项参照下图:
image.png
image.png
image.png

2.2.本地化操作2.2.1.配置sshkey,实现免密提交

在git bash里执行 ssh-keygen -t rsa -C "abc@xyz.com",可以不输入密码
在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 "abc@xyz.com"
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 <file name> # 从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"

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。
下一篇: Mac. git ssh配置

Tags 标签

git

扩展阅读

加个好友,技术交流

1628738909466805.jpg