【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
相关推荐
b1ng5 小时前
新人程序员 Git 一站式指南
git·github
程序员的世界你不懂6 小时前
IDE 关联 Git 操作
ide·git
weixin_428498497 小时前
Git Submodule 介绍和使用指南
git
jingshaoqi_ccc19 小时前
GitKraken最后一个免费版本和下载地址
git·github·gitkraken·版本管理工具
乌云暮年19 小时前
Git简单命令
git·gitee·github·batch命令
用户1259265423201 天前
使用 Docker 搭建 Gitea 并实现 Git HTTP 自动登录
git
一只毛驴1 天前
谈谈对git stash的理解?
git
长风破浪会有时呀1 天前
Git 学习笔记
笔记·git·学习
中微子2 天前
Git Rebase 详解:概念、原理与实战示例
git
荔枝吻2 天前
【保姆级喂饭教程】Windows下安装Git Flow
windows·git·git flow