// todo 学习.git文件的原理
- 设置方式如下:
git config —global user.name “自行设置”
git config —global user.mail “设置可以真正使用的邮箱”
- 查看全局设置:
git config —list
//todo 除了查看global,再仔细研究一下local和system这两个选项
工作区:working directory,对应文件刚刚被创建,未被git track到 缓存区:staging area,文件被提交到缓存区,被git所跟踪 仓库:repository,执行完commit指令后,文件保存到下一个版本中,处于已经 提交的状态
git add
Untracked files: (use "git add ..." to include in what will be committed)
git commit -m “create learn_git.html” [git log]
Changes to be committed: (use "git rm --cached ..." to unstage)
提交完成之后:git status
On branch master nothing to commit, working tree clean
打开github,创建仓库 使用https协议:每次都需要输入密码,较为繁琐,若想不输入密码的话,会本 地保存明文密码,很不安全,不推荐 使用ssh协议:第一次使用的时候,创建好git密钥【公钥,私钥】即可
git remote add origin [email protected]:******/learn_git.git
注释: origin 远程仓库别名,可以自行更改 执行完成之后可以检验一下是否添加成功:git remote
ssh-keygen -t rsa -C “******@qq.com”
执行:ssh -T [email protected]
git push -u origin master
or
git push -u origin main
Git生成密钥后将密钥配置到Github上,但是每次提交代码的时候还是要输入用户名和密码。操作步骤很是麻烦。
因为用的是https而不是ssh,更新origin为ssh格式即可。 https的格式为:https://github.com/用户名/仓库名.git ssh的格式为:[email protected]:用户名/仓库名.git
git remote remove origin
git remote add origin [email protected]:用户名/仓库名.git
此时提交代码可以不用重复输入用户名与密码了,但是问题来了:当你拉代码的时候,会报如下错误:
From github.com:用户名/项目名
- [new branch] main -> origin/main There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/ main
git branch --set-upstream-to=origin/main main
or
git branch --set-upstream-to=origin/<branch> main
warning: LF will be replaced by CRLF in 原因是存在符号转义问题 windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示,解决办法:
git config --global core.autocrlf false