Git 学习笔记
笔记来源视频链接:黑马程序员Git全套教程,完整的git项目管理工具教程,一套精通git_哔哩哔哩_bilibili
Git 基础命令操作(本地仓库)
配置 用户名和Email
右键打开 Git Bash:
[*]git config --global user.name "用户名"
[*]git config --global user.email "邮箱地址"
Git 结构
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437230-1455751327.png
1. 创建本地仓库
(1)创建一个空目录
(2)初始化本地仓库
[*]空目录下,右键选择,git bash
[*]使用 git init
2. 为仓库添加文件
[*]使用命令创建文件 touch file1.txt
[*]可以查看当前状态 git status
[*]将文件添加到暂存区 git add file1.txt
[*]查看状态 git status
[*]将暂存区的文件提交到本地仓库 git commit -m "add fiel1"
[*]查看状态 git status
[*]查看日志 git log
3. 修改文件
[*]使用vi编辑器添加一些内容(上面file1无内容) vi file1.txt
[*]查看状态 git status
[*]将文件添加到暂存区 git add file1.txt
[*]查看状态 git status
[*]将暂存区的文件提交到本地仓库 git commit -m "chage file1"
[*]查看状态 git status
[*]查看日志 git log
4. 查看提交日志
[*]git log
[*]git log --graph
[*]git log --pretty=online
[*]...
5. 版本回退
现在要回到file1最开始的版本(无内容)
[*]git reset --hard 【commit ID(通过git log查看)】
[*]查看commit ID: git reflog
6. 创建无需要提交到本地仓库的文件设置
在创建的git目录中,有些文件不需要提交本地仓库。
[*]创建file2.txt :touch file2.txt
[*]创建 .gitignore文件(可以在该文件内设置不需要到仓库的文件): touch .gitignore
[*]编辑.gitignore(在里面加 file2.txt):vi .gitignore
[*]查看状态【发现不在提示file2为提交了】:git ststus
7. 删除文件
[*]rm .gitignore
[*]【删除 .gitignore文件之后,发现file2.txt又出现未提交提示了】:git status
8. 分支
8.1 基础操作
使用分支意味着你可以把你的工作从开发主线上分离开来进行重大的Bug修改、开发新的功能,以免影响开发主线
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437222-546211954.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437532-953320175.png
8.2 开发中使用流程
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437408-398025033.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436979-869565566.png
总结
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436575-957482403.png
Git 远程操作(远程仓库)
Git 工作流程图
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437380-643290197.png
常用的托管服务【远程仓库】
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436713-153847717.png
1. 创建远程仓库——这里使用Gitee
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437108-847330645.png
创建好了后
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437136-2081643670.png
2. 配置SSH公私钥
如果我们想要把本地仓库送到远程仓库,这需要验证我们的身份,才能托管。
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436713-1371290798.png
在本地操作——生成公钥
(1)生成公钥
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436971-1222663669.png
(2)查看公钥
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436519-1950443306.png
Gitee网页操作——将本地生成的公钥放在远程账号里
(1)
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437017-1213902400.png
(2)
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436900-439360619.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436887-1736078385.png
验证是否成功
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436939-1921388902.png
3. 把本地仓库推到远程仓库
(1)把远程仓库的地址复制下来
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436539-902742439.png
(2)告诉本地仓库,你所对应的远程仓库是哪一个
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436484-989171867.png
4. 查看远程仓库
[*]git remote
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436972-1478476758.png
5. 将本地代码同步到远程仓库
[*]git push orgin master
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436461-1760755057.png
刷新gitee,可以看到已经推送成功了。
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436611-1427808114.png
6. 从远程仓库克隆
从远程仓库拉取到本地。
(1)重新创建一个仓库
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437084-1923051304.png
(2)找要克隆的远程仓库的地址
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437067-1667662526.png
(3)本地操作 clone
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436535-80667272.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436976-675929889.png
(4)对比:拉到远程的 和 从远程克隆下来的 是一样的
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437113-1148515653.png
7. 从远处仓库抓取和拉取
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436682-1555758115.png
8. 解决合并冲突
和解决本地冲突一样的。
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436707-1957496908.png
总结——远程仓库操作
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437228-413829681.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073436827-1667967026.png
简单操作:
[*]查看本地分支与远程分支的关系:git branch -vv
[*]绑定远程和本地分支:git branch --set-upstream orign master:master
[*]再次查看https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437070-984654786.png
[*]这样下次push的时候直接使用:git push 【即可】
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437417-1717780345.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437234-223234189.png
https://img2023.cnblogs.com/blog/2996408/202306/2996408-20230608073437463-961775202.png
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! 不错,里面软件多更新就更好了 感谢,下载保存了
页:
[1]