【Git】git基础

Git

命令

bash 复制代码
git config --globle user.name ""

git config --globle user.email ""

git config -l

git config --globle --unset []

git add []

git commit -m ""]

git log

//当行且美观
git log --pretty=oneline

//以图形化和简短的方式
git log --graph --abbrev-commit

git cat-file -p [3a6640b795dd96f8d1d4f7574c9db489cdc1a2ab]

git status

git diff file_name

版本回退

bash 复制代码
git reset [ --soft | --mixed | --hard ] [3a6640b795dd96f8d1d4f7574c9db489cdc1a2ab]

op:
--soft : 只回退版本库,工作区和暂存区不回退。
--mixed : 回退版本库和暂存区,工作区不回退。(default op)
--hard : 全部都要回退


git reflog

撤销

只在工作区

bash 复制代码
//将工作区回退到当前版本
git checkout --[file_name]

在工作区和暂存区

bash 复制代码
//版本库和暂存区回退到当前版本
git reset HEAD  [--mixed | --hard]



//工作区回退到当前版本
git checkout -- [file_name]

在工作、暂存、版本区

前提: commit 之后 没有 push

bash 复制代码
//版本库和暂存区回退到上个版本
git reset HEAD^  [--mixed | --hard]

//工作区回退到当前版本
git checkout -- [file_name]

删除

bash 复制代码
//删除工作区和暂存区的内容
git rm [file_name]

git commit -m ""

分支

分支管理

bash 复制代码
//查看分支
git branch

//创建一个分支
git branch branch_name

//更换当前分支
git checkout branch_name

//创建并更换当前分支
git checkout -b branch_name

//合并分支
git merge branch_name

//删除分支
git branch -d branch_name

//分支未合并,但已经提交
git branch -D branch_name

分支冲突

merge 冲突需要手动解决,并且需要进行一次提交。

合并分支的时候最好使用no fast forward模式,以便于溯源提交。

bash 复制代码
git merge -no-ff -m "merge dev2" dev2
bash 复制代码
//将工作区内容保存
git stash

git stash pop

远程操作

bash 复制代码
git clone url

git remote -v  

使用ssh克隆仓库

bash 复制代码
ssh-keygen -t rsa -C "email地 址"

//再将ssh公钥配置对应的平台

推送

bash 复制代码
//本地:远程 分支名称相同可以省略
git push origin master:master

git push origin branch_name

拉取

bash 复制代码
//远程:本地 分支名称相同可以省略
git pull origin master:master

配置.gitignore

bash 复制代码
# 排除
*.so
*.cc
# 不排除
!c.so
bash 复制代码
//强制提交忽略文件
git add -f file_name

git check-ignore -v file_name

git配置

bash 复制代码
//git st
git config --global alias.st status

//git lpa
git config --global alias.lpa 'log --pretty=oneline --abbrev-commit'

标签管理

针对最后一次 commit 起一个 v1.0 的标签

bash 复制代码
git tag v1.0 commitId

git tag

git tag -a v0.8 -m "important"

git show v0.8

git tag -d v0.9

//本地删除v1.0,再推送远端
git push origin:v1.0

git push origin v1.0

//推送所有标签
git push origin --tags

多人协作

bash 复制代码
git branch -r

git branch -a

//查看链接情况
git branch -vv

//两种链接方式:
git branch --set-upstream-to=origin/dev dev

git checkout -b dev origin/dev

git pull
# 1拉取分支内的内容
# 2拉取仓库的内容(不用建立链接 )

各自负责对应的分支

远程删除分支后,本地依然能看到

bash 复制代码
git remote show origin

git remote prune
相关推荐
Good_Starry13 小时前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
云端奇趣18 小时前
探索 3 个有趣的 GitHub 学习资源库
经验分享·git·学习·github
F_D_Z1 天前
【解决办法】git clone报错unable to access ‘xxx‘: SSL certificate problem:
网络·git·网络协议·ssl
等风来不如迎风去1 天前
【git】main|REBASE 2/6
git
艾伦~耶格尔1 天前
IDEA 配置 Git 详解
java·ide·git·后端·intellij-idea
云兮杜康1 天前
IDEA中用过git之后文件名颜色全变红
java·git·intellij-idea
睡不醒的小泽1 天前
git merge 和 git rebase
git
艾伦~耶格尔1 天前
Git 下载及安装超详教程(2024)
git·gitee·码仓
weixin_438197381 天前
linux部署redis,整合ansible和redis
linux·redis·git
安全在心中1 天前
gitee公钥设置、创建库及使用
git·gitee