0


【Git】git基础

Git

命令

git config --globle user.name ""git config --globle user.email ""git config -lgit config --globle--unset[]gitadd[]git commit -m""]git log

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

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

git cat-file -p[3a6640b795dd96f8d1d4f7574c9db489cdc1a2ab]git status

gitdiff file_name

版本回退

git reset [--soft|--mixed|--hard][3a6640b795dd96f8d1d4f7574c9db489cdc1a2ab]

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

git reflog

撤销

只在工作区

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

在工作区和暂存区

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

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

在工作、暂存、版本区

前提: commit 之后 没有 push

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

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

删除

//删除工作区和暂存区的内容
gitrm[file_name]git commit -m""

分支

分支管理

//查看分支
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模式,以便于溯源提交。

git merge -no-ff -m"merge dev2" dev2
//将工作区内容保存
git stash

git stash pop

远程操作

git clone url

git remote -v

使用ssh克隆仓库

ssh-keygen -t rsa -C"email地 址"

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

推送

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

git push origin branch_name

拉取

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

配置.gitignore

# 排除
*.so
*.cc
# 不排除!c.so
//强制提交忽略文件
gitadd-f file_name

git check-ignore -v file_name

git配置

//git st
git config --global alias.st status

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

标签管理

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

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

多人协作

git branch -rgit branch -a

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

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

git checkout -b dev origin/dev

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

各自负责对应的分支

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

git remote show origin

git remote prune
标签: git

本文转载自: https://blog.csdn.net/m0_73209194/article/details/135304588
版权归原作者 蓝色学者i 所有, 如有侵权,请联系我们删除。

“【Git】git基础”的评论:

还没有评论