> 文章列表 > git版本控制

git版本控制

git版本控制

git版本控制

time:2023-04-18

  • 版本控制

  • 集中式版本控制

  • 多人协作开发

创建仓库

使用当前目录作为 Git 仓库,我们只需使它初始化。

git init

使用我们指定目录作为Git仓库。

git init newrepo

克隆远程仓库

git clone https://gitee.com/zhang-mingming123/smart-charge-station.git

配置仓库信息

#配置当前仓库的用户信息
git config user.name "zmm"
git config user.email "196702@qq.com"
#配置全局的用户信息
git config --global user.name "zmm"
git config --global user.email "196702@qq.com"

git版本控制

  • workspace:工作区
  • staging area:D:\\19670\\Pictures\\Screenshots暂存区/缓存区
  • local repository:版本库或本地仓库
  • remote repository:远程仓库

提交与修改

添加文件到暂存区

git add .

查看仓库当前的状态,显示有变更的文件。

git status

比较文件的不同,即暂存区和工作区的差异。

git diff

提交暂存区到本地仓库。

git commit -m "commit message"

回退版本 这个会丢失提交信息

git reset --hard 版本号

恢复

git revert 版本号

查看历史提交

git log

分支操作

19670@ming MINGW64 /d/code/hmdp/hm-dianping (zset-score-timestrep)
$ git branchmasterstreamqueue
* zset-score-timestrep19670@ming MINGW64 /d/code/hmdp/hm-dianping (zset-score-timestrep)
$ git branch -vmaster               82d58fc 使用阻塞队列来优化秒杀优惠券!streamqueue          130f9e3 使用redis的stream队列来优化秒杀优惠券!
* zset-score-timestrep 44dca4e 使用redis的geo实现附近店铺!#删除分支
git branch -d 分支名
#创建分支
git branch 分支名
#切换分支
git checkout 分支名
#合并分支 合并指定分支到当前分支 如果有冲突则需要处理
git merge 分支名

标签

查看所有标签

git tag

指定标签信息命令:

git tag -a <tagname> -m "runoob.com标签"

git config文件

[core]repositoryformatversion = 0filemode = falsebare = falselogallrefupdates = truesymlinks = falseignorecase = true
[remote "origin"]url = https://gitee.com/zhang-mingming123/.gitfetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]remote = originmerge = refs/heads/master
[branch "streamqueue"]remote = originmerge = refs/heads/streamqueue
[branch "zset-score-timestrep"]remote = originmerge = refs/heads/zset-score-timestrep

全局的配置会在 .gitconfig文件里面

git版本控制

.gitconfig

[user]name = email = 

远程仓库

添加远程仓库 ssh需要公钥认证

git remote add origin 地址(http地址||ssh地址)
#公钥生成 
ssh-keygen -t rsa -C ssh地址
#移除远程仓库
git remote remove origin
git remote rename origin
#推送到远程仓库
git push origin
#拉取远程仓库
git pull origin 

idea集成git

git版本控制

``

#移除远程仓库
git remote remove origin
git remote rename origin
#推送到远程仓库
git push origin
#拉取远程仓库
git pull origin 

idea集成git

[外链图片转存中…(img-Cw5z0ayY-1681873443466)]