GIT的使用

0.Git参考

Git参考(就看这个):https://blog.csdn.net/weixin_48152652/article/details/124258293

Git命令大全:https://baijiahao.baidu.com/s?id=1750089046854021842&wfr=spider&for=pc

1.Git原理

原理参考:https://mp.weixin.qq.com/s?__biz=MzI5ODI5NDkxMw==&mid=2247605193&idx=6&sn=3782c35820f18bc2a56c9a8d51077a77&chksm=ecab1027dbdc9931433f6dba7153dd130dcdbe13b37fb5df9a8e74f4dfb78e539d37a8fa0cd1&scene=27

新命令:https://blog.csdn.net/m0_55635384/article/details/128993409

1.1 Git基本概念

文件状态:已修改(modified)、已暂存(staged)、已提交(committed)

commit节点

head:指针

image-20230418162903672

img

workplace: 本地目录
index: 缓存区,具体体现在本地的.git/head文件中  
Repository: 本地仓库
Remote: 远程仓库---->分支

2. Gitee创建项目

image-20230418144927170

gitee Username:fubob
gitee 密钥:6f0e07915fa0b2e046c328094008b6bf

github username: bobofueeeee
github 密钥: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


手动下载项目

cd 项目目录
git init
git remote add origin https://github.com/multifiai/multifi.git
git remote -v

成功会出现

origin https://github.com/multifiai/multifi.git (fetch)
origin https://github.com/multifiai/multifi.git (push)

3. Git常用命令

git config --global user.name "fubobo"   ## gitee
git config --global user.email "12810137+fubob@user.noreply.gitee.com"

################# 1.第一次上传代码 #################
## 第一次上传代码,记得初始化,并作第一次拉取,不然本地不会有分支
git init
git remote add origin https://gitee.com/fubob/project-follow-up.git
方式一:git fetch; git checkout master
git add .
git commit -m '第一次提交'
git push -u origin "master" 


################# 2.拉取文件并修改 #################
git init
git remote add origin https://gitee.com/fubob/project-follow-up.git

方式一:git fetch; git checkout master
方式三:git pull origin master 
方式二(不推荐,不创建分支):git clone https://gitee.com/fubob/project-follow-up.git
git branch -a
git checkout workplace

修改后
git add xxx
git commit -m "xxxx"
git push -u origin "master"

############################ 分支操作 ############################
git init
# 拉取分支
git pull https://gitee.com/LzMingYueShanPao/dsmm_model.git dsmm_dev
fubob
6f0e07915fa0b2e046c328094008b6bf

git branch # 查看分支
git checkout -b 分支名 master # 创建分支
git pull origin dsmm_dev
# 代码更新
git add xxx
git commit -m "xxxx"
git push -u origin dsmm_dev

4. Git命令大全

################# Git账号本地注册 #################
git config --global user.name "bobofueeeee"   ## github
git config --global user.email "fubogongzuo@163.com"

git config --global user.name "fubobo"   ## gitee
git config --global user.email "12810137+fubob@user.noreply.gitee.com"

# Git账号查询
git config -l ## 查看当前git环境详细配置
git config --system --list  ## 查看系统config,配置文件在git安装目录/etc/gitconfig
git config --global --list  ## 查看当前用户配置,配置文件在~/.gitconfig
git config --local --list  ## 查看当前仓库配置信息,配置文件在当前项目的/.git/config

################# Git初始化 #################
# 进入到项目目录,打开git终端
git init

################# Git上传 #################
git add README.md                                               ## 添加到缓存取
git commit -m "first commit"									## 提交到本地仓库
git remote add origin https://gitee.com/fubob/project-follow-up.git		## 连接远程仓库
git push -u origin "master"										## 提交到master分支,-f 强制提交

################# Git拉取 #################
# 4.1 拉取整个项目
git clone https://gitee.com/fubob/note-pic.git

# 4.2 拉取单个文件   git show <commit_id>:<file_path> > <destination_path>
git show 8d093a41c66d28bffe9d5d5ba6370b80e8703f12:work.xlsx > test.xlsx
git show 245f8ee8d14e4907116aa5621d6baa4df9b40ae9:2\ 分类/代码/test.txt > test.txt

# 4.3 拉取单个文件夹 
git fetch origin master
git checkout master -- test/test.txt


################# 缓存区操作 #################
git ls-files --cached  ## 查询缓存区文件
git add . ## 添加文件到缓存区
git add -u . ## u指update,将工作区的被修改的文件和被删除的文件提交到暂存区,不包括新增的文件
git add -A . ## A指all,将工作区被修改、被删除、新增的文件都提交到暂存区
git rm -rf . --cached  ## 删除文件从缓存区
git reset HEAD ## 要移出的文件名称

################# 本地仓库操作 #################
git rm file  			## 删除本地仓库文件
git rm -rf . 			## 删除本地仓库所有文件
git mv file1 file2      ## 重命名本地仓库文件

git reset --soft HEAD^ 			
# 撤销commit 
## -- HEAD^=HEAD~1(两次撤销HEAD~2) 
## --mixed 撤销 commit、并撤销 git add. 操作、不撤销修改代码 
## -- soft 撤销 commit、不撤销git add . 
## -- hard 撤销 commit、撤销 git add . 操作、撤销修改代码


################# 远程仓库操作 #################
git remote ## 查看本地添加了哪些远程分支地址
git remote -v ## 查看本地添加了哪些远程分支地址更详细信息
git remote rm origin  ## 删除当前远程仓库
git remote add origin 远程地址 ## 关联远程仓库

git push -u origin "master" ##第一次提交需要加 -u参数后
git push ## 将文件添加到远程仓库
git push -f ## 强制提交,当我们本地reset到旧的版本时,然后普通push会被拦截,因为此是本地HEAD指向比远程库还要旧
git push origin [branch-name] ## 推送当前本地分支到指定远程分支


################# 4. Git分支操作 #################
git branch				## 查看当前分支 -a 显示所有(本地+远程) -r 显示远程分支 -v:显示最后一次提交的分支
git branch <branch>		## 创建分支
git checkout <branch>	## 切换分支
git checkout -b <branch>## 创建并切换分支
git branch -d <branch>  ## 删除分支
git branch -D <branch>  ## 强制删除分支
git merge <branch to merge into HEAD>  ## 合并分支

################# 4. Git获取commit id #################
git log

merge/diff/????

5. Git使用记录

5.1 使用记录

image-20230418145056105

image-20230418145329682

image-20230418145638122


image-20230418155035460

5.2 常见问题

鉴权失败:https://www.yii666.com/blog/374034.html

image-20230410143714347

上传文件大小超过100M

# 方法一:全局配置 git config --global http.postBuffer 524288000  
或者  
# 方法二:当前仓库配置 git config http.postBuffer 524288000

git push不成功后,如何删除这部分代码

git reset --soft HEAD^  ## 撤销最近一次commit,不撤销add  ## -- HEAD^=HEAD~1(HEAD~2撤销最近两次commit)

fatal: invalid reference: master

git branch -a 显示的是空的
找一个文件修改一下,进行commit操作,然后push上去
posted @ 2023-06-28 15:30  付十一。  阅读(3)  评论(0)    收藏  举报