git 的基础
作者:互联网
官网:https://git-scm.com/
设置用户名与邮箱
尘曦@▒▒▒▒ 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
初始化一个仓库
$ 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
提交变更
尘曦@▒▒▒▒ 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
添加文件
$ 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
修改文件提交变更
尘曦@▒▒▒▒ 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
重命名文件名操作
尘曦@▒▒▒▒ 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 历史查看
$ 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 :
标签:git,尘曦,基础,MINGW64,master,learning,commit 来源: https://www.cnblogs.com/rdchenxi/p/14753675.html