git 的基础
官网:https://git-scm.com/
设置用户名与邮箱
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --global user.name "ruidongchenxi" 设置用户名 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --global user.email "rdchenxi@163.com" 添加账户 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config -- local 表示只对指定的仓库生效 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --global 对当前用户所有仓库生效 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --system 对系统所有账户有效 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --list -- local fatal: -- local can only be used inside a git repository 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --list --global user.name=rdcx user.email=rdchenxi@163.com 尘曦@▒▒▒▒ MINGW64 ~ /Desktop $ git config --list --system diff .astextplain.textconv=astextplain filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required= true http.sslbackend=openssl http.sslcainfo=D: /tool/git/Git/mingw64/ssl/certs/ca-bundle .crt core.autocrlf= true core.fscache= true core.symlinks= false pull.rebase= false credential.helper=manager-core credential.https: //dev .azure.com.usehttppath= true init.defaultbranch=master |
初始化一个仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $ git init git_learning Initialized empty Git repository in D: /git_learning/ .git/ 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git config -- local user.name 'cx' 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git config -- local user.email '1397506052@qq.com' 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git config -- local --list core.repositoryformatversion=0 core.filemode= false core.bare= false core.logallrefupdates= true core.symlinks= false core.ignorecase= true user.name=cx user.email=1397506052@qq.com |
提交变更
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ cp .. /SQLyog/Keywords .db . 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ ls Keywords.db 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add Keywords.db 添加变更文件 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git commit -m '123' [master (root-commit) ef438c5] 123 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Keywords.db 执行变更操作 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ cp .. /SQLyog/SQLyog .chm . 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add SQLyog.chm 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status 查看给git状态 On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file : SQLyog.chm $ git log 查看git 变更日志 commit ef438c5022f5b9549fb5408629e9d470c9330cb6 (HEAD -> master) Author: cx <1397506052@qq.com> 变更作者 local 优先及高 Date: Tue May 11 00:44:26 2021 +0800 123 |
添加文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | $ git status 查看git状态 On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file : SQLyog.chm Untracked files: (use "git add <file>..." to include in what will be committed) AuthStatusEnum.java 表示没有被git管理的文件 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add AuthStatusEnum.java 添加为git管理 warning: LF will be replaced by CRLF in AuthStatusEnum.java. The file will have its original line endings in your working directory $ git status On branch master Changes to be committed: 暂存去 (use "git restore --staged <file>..." to unstage) new file : AuthStatusEnum.java new file : SQLyog.chm 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git commit -m "ADD java" 暂存区文件提交操作 [master 1b6cf68] ADD java 2 files changed, 45 insertions(+) create mode 100644 AuthStatusEnum.java create mode 100644 SQLyog.chm $ mkdir css 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ cp /d/ 医疗项目--尚医通/资料/资料 /01- 项目实体和vo类 /model/com/atguigu/yygh/enums/DictEnum .java css/ 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) css/ nothing added to commit but untracked files present (use "git add" to track) 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ ls AuthStatusEnum.java Keywords.db SQLyog.chm css/ 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ ls css/ DictEnum.java 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add css 添加暂存区操作 warning: LF will be replaced by CRLF in css /DictEnum .java. The file will have its original line endings in your working directory 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file : css /DictEnum .java 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git commit -m "qwe" 提交变更 [master 785c674] qwe 1 file changed, 33 insertions(+) create mode 100644 css /DictEnum .java 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git log 查看变更日志 commit 785c6743a82a2796193b05718199e5622361083c (HEAD -> master) Author: cx <1397506052@qq.com> Date: Tue May 11 01:06:27 2021 +0800 qwe commit 1b6cf6858db65acf1055208b2fe16ba065203051 Author: cx <1397506052@qq.com> Date: Tue May 11 01:01:28 2021 +0800 ADD java commit ef438c5022f5b9549fb5408629e9d470c9330cb6 Author: cx <1397506052@qq.com> Date: Tue May 11 00:44:26 2021 +0800 123 |
修改文件提交变更
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ vim AuthStatusEnum.java 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status 查看状态 On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: AuthStatusEnum.java no changes added to commit (use "git add" and /or "git commit -a" ) 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add -u 将已经被git 管理的文件并且有变更的文件一起提交暂存区 warning: LF will be replaced by CRLF in AuthStatusEnum.java. The file will have its original line endings in your working directory 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status 查看状态 On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: AuthStatusEnum.java $ git commit -m "修改部分文件" 提交变更 [master 4eba0ca] 修改部分文件 1 file changed, 1 insertion(+) 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git log 查看日志 commit 4eba0ca72e8a1d7245a69ab0fb32199a94d17722 (HEAD -> master) Author: cx <1397506052@qq.com> Date: Tue May 11 01:16:29 2021 +0800 修改部分文件 commit 785c6743a82a2796193b05718199e5622361083c Author: cx <1397506052@qq.com> Date: Tue May 11 01:06:27 2021 +0800 qwe commit 1b6cf6858db65acf1055208b2fe16ba065203051 Author: cx <1397506052@qq.com> Date: Tue May 11 01:01:28 2021 +0800 ADD java commit ef438c5022f5b9549fb5408629e9d470c9330cb6 Author: cx <1397506052@qq.com> Date: Tue May 11 00:44:26 2021 +0800 123 |
重命名文件名操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ mv Keywords.db Keywords 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: Keywords.db Untracked files: (use "git add <file>..." to include in what will be committed) Keywords no changes added to commit (use "git add" and /or "git commit -a" ) 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add -u 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) deleted: Keywords.db Untracked files: (use "git add <file>..." to include in what will be committed) Keywords 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git add Keywords 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git rm Keywords.db fatal: pathspec 'Keywords.db' did not match any files 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) renamed: Keywords.db -> Keywords 还原操作 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git reset --hard HEAD is now at 4eba0ca 修改部分文件 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master nothing to commit, working tree clean 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ ls AuthStatusEnum.java Keywords.db SQLyog.chm css/ 简单重命名方法 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git mv Keywords.db Keywords $ ls AuthStatusEnum.java Keywords SQLyog.chm css/ 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) renamed: Keywords.db -> Keywords $ git commit -m "zuo" [master e986ad1] zuo 1 file changed, 0 insertions(+), 0 deletions(-) rename Keywords.db => Keywords (100%) 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git log commit e986ad128754afafe01178121dd567aa0c9e2060 (HEAD -> master) Author: cx <1397506052@qq.com> Date: Tue May 11 01:29:26 2021 +0800 zuo commit 4eba0ca72e8a1d7245a69ab0fb32199a94d17722 Author: cx <1397506052@qq.com> Date: Tue May 11 01:16:29 2021 +0800 修改部分文件 commit 785c6743a82a2796193b05718199e5622361083c Author: cx <1397506052@qq.com> Date: Tue May 11 01:06:27 2021 +0800 qwe commit 1b6cf6858db65acf1055208b2fe16ba065203051 Author: cx <1397506052@qq.com> Date: Tue May 11 01:01:28 2021 +0800 ADD java |
git 历史查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | $ git log --oneline 简洁方式查看git 历史 e986ad1 (HEAD -> master) zuo 4eba0ca 修改部分文件 785c674 qwe 1b6cf68 ADD java ef438c5 123 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git log -n 2 查看最近两次变更更 commit e986ad128754afafe01178121dd567aa0c9e2060 (HEAD -> master) Author: cx <1397506052@qq.com> Date: Tue May 11 01:29:26 2021 +0800 zuo commit 4eba0ca72e8a1d7245a69ab0fb32199a94d17722 Author: cx <1397506052@qq.com> Date: Tue May 11 01:16:29 2021 +0800 修改部分文件 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git log -n 2 --oneline 简洁显示 e986ad1 (HEAD -> master) zuo 4eba0ca 修改部分文件 $ git branch - v 查看本地支 * master e986ad1 zuo 尘曦@▒▒▒▒ MINGW64 /D/git_learning (master) $ git checkout -b temp 4eba0ca 创建分支 Switched to a new branch 'temp' 尘曦@▒▒▒▒ MINGW64 /D/git_learning (temp) $ vim AuthStatusEnum.java 修改操作 尘曦@▒▒▒▒ MINGW64 /D/git_learning (temp) $ git commit -am "wec" 直接提交代码 warning: LF will be replaced by CRLF in AuthStatusEnum.java. The file will have its original line endings in your working directory [temp caae240] wec 1 file changed, 1 insertion(+), 1 deletion(-) 尘曦@▒▒▒▒ MINGW64 /D/git_learning (temp) $ git branch - v 查看分支 master e986ad1 zuo * temp caae240 wec 查看日志 尘曦@▒▒▒▒ MINGW64 /D/git_learning (temp) $ git log commit caae2401c9c7d4b2af7f64618d2592b26406bd84 (HEAD -> temp) Author: cx <1397506052@qq.com> Date: Tue May 11 01:38:03 2021 +0800 wec commit 4eba0ca72e8a1d7245a69ab0fb32199a94d17722 Author: cx <1397506052@qq.com> Date: Tue May 11 01:16:29 2021 +0800 修改部分文件 commit 785c6743a82a2796193b05718199e5622361083c Author: cx <1397506052@qq.com> Date: Tue May 11 01:06:27 2021 +0800 qwe 尘曦@▒▒▒▒ MINGW64 /D/git_learning (temp) $ git log --all 查看所以分支历史 commit caae2401c9c7d4b2af7f64618d2592b26406bd84 (HEAD -> temp) Author: cx <1397506052@qq.com> Date: Tue May 11 01:38:03 2021 +0800 wec commit e986ad128754afafe01178121dd567aa0c9e2060 (master) Author: cx <1397506052@qq.com> Date: Tue May 11 01:29:26 2021 +0800 zuo commit 4eba0ca72e8a1d7245a69ab0fb32199a94d17722 Author: cx <1397506052@qq.com> 尘曦@▒▒▒▒ MINGW64 /D/git_learning (temp) $ git log --all --graph 清晰的查看 * commit caae2401c9c7d4b2af7f64618d2592b26406bd84 (HEAD -> temp) | Author: cx <1397506052@qq.com> | Date: Tue May 11 01:38:03 2021 +0800 | | wec | | * commit e986ad128754afafe01178121dd567aa0c9e2060 (master) |/ Author: cx <1397506052@qq.com> | Date: Tue May 11 01:29:26 2021 +0800 | | zuo | * commit 4eba0ca72e8a1d7245a69ab0fb32199a94d17722 | Author: cx <1397506052@qq.com> | Date: Tue May 11 01:16:29 2021 +0800 | | 修改部分文件 | * commit 785c6743a82a2796193b05718199e5622361083c | Author: cx <1397506052@qq.com> | Date: Tue May 11 01:06:27 2021 +0800 | | qwe : |
草都可以从石头缝隙中长出来更可况你呢
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏