1 Git基本配置
当安装Git后首先要做的事情是设置用户名称和email地址。这是非常重要的,因为每次Git提交都会使用该用户信息。
-
打开Git Bash
-
设置用户信息
git confifig --global user.name “itcast”git confifig --global user.email “hello@itcast.cn”查看配置信息
git confifig --global user.namegit confifig --global user.email
2 创建本地仓库
要使用Git对我们的代码进行版本控制,首先需要获得本地仓库:
1)在电脑的任意位置创建一个空目录(例如test)作为我们的本地Git仓库。
2)进入这个目录中,点击右键打开Git bash窗口。
3)执行命令git init。
4)如果创建成功后可在文件夹下看到隐藏的.git目录。
git init
3 基础git操作命令
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test/.git (GIT_DIR!)$ cd ..
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ touch file.txt
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git statusOn branch master
No commits yet
Untracked files: (use "git add <file>..." to include in what will be committed) file.txt
nothing added to commit but untracked files present (use "git add" to track)
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git add .
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git statusOn branch master
No commits yet
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: file.txt
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git commot -m "add file"git: 'commot' is not a git command. See 'git --help'.
The most similar command is commit
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git commit -m "add file"[master (root-commit) 36806c9] add file 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 file.txt
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git statusOn branch masternothing to commit, working tree clean
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git logcommit 36806c9633d85f2200f9277c9a6b0b196780b866 (HEAD -> master)Author: studentliuchang <773395726@qq.com>Date: Fri Aug 12 16:11:31 2022 +0800
add file
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ vi file.txt
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ cat file.txt
updata count01 =1
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git statusOn branch masterChanges 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: file.txt
no changes added to commit (use "git add" and/or "git commit -a")
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git add .warning: LF will be replaced by CRLF in file.txt.The file will have its original line endings in your working directory
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git statusOn branch masterChanges to be committed: (use "git restore --staged <file>..." to unstage) modified: file.txt
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git commit -m "updata file01"[master e70b970] updata file01 1 file changed, 2 insertions(+)
77339@LAPTOP-59ARH7U0 MINGW64 ~/Desktop/test (master)$ git logcommit e70b970b3b95354337b57fe8fb9b3eebe62ce293 (HEAD -> master)Author: studentliuchang <773395726@qq.com>Date: Fri Aug 12 16:15:01 2022 +0800
updata file01
commit 36806c9633d85f2200f9277c9a6b0b196780b866Author: studentliuchang <773395726@qq.com>Date: Fri Aug 12 16:11:31 2022 +0800
add file
4 Git远程仓库
在码云上创建仓库:
验证密钥是否配置成功:
ssh -T git@gitee.com# 添加远程仓库git remote add <远端名称> <仓库路径># 查看远程仓库git remote# 推送到远程仓库git push [-f] [--set-upstream] [远端名称 [本地分支名][:远端分支名] ]
5 IDEA使用Git
5.1 配置Git
5.2 初始化本地仓库
配置.gitignore文件:
# IntelliJ project files.idea*.imloutgen/.apt_generated//.classpath/.factorypath/.project/.settings//.springBeans/target//.gitignore/user-profile-analysis.iml/.idea/README.md.DS_Store
5.3 创建远程仓库
5.4 更改提交
5.5 克隆到本地
修改后再次上传:
创建分支:
6 使用游戏学习Git