这里举例 :https://codechina.csdn.net/ 这个平台 CODE CHINA
git下载官网:https://git-scm.com/downloads
可借鉴教程:https://chuanchuan.blog.csdn.net/article/details/119993523
新手入门:
配置git
打开git窗口,分别输入如下命令:
- 配置用户名:git config --global user.name "这里自定义用户名"
- 配置邮箱:git config --global user.email 邮箱
- 生成秘钥: ssh-keygen -t rsa -C '邮箱'
多次回车就行
会在 C:\Users\Administrator\.ssh 中的 id_rsa.pub 文件夹中显示生成的秘钥,要复制,有用
在对应的网站的个人设置选项中 找到 SSH密钥这个选项 把刚刚复制的密钥粘贴到对应的位置 点击确定
关联远程仓库:
- git remote add origin 项目ssh地址 ,及 克隆选项的展开
克隆项目:
- git clone 项目ssh地址
(可选)给克隆下来的文件取个别名: git clone 项目ssh地址 别名
上传文件:
- 关联远程仓库:git remote add origin ssh项目地址
- cd到下载的文件中 cd 文件名
- 初始化本地仓库:git init
- 在下载的文件夹中 添加 自己要上传的文件
- (可选):查看远程仓库状态:git status
- 提交到暂缓区:git add .
- 提交文件:git commit -m "随便来个注释"
(可选)提交单个文件: git commit -m "随便来个注释" 文件名
- 获取远程库于本地同步合并:git pull --rebase origin master
- 更新同步远程仓库:git push -u origin master
- 刷新仓库即可看到上传的文件
一些基本命令:
查看已经关联的仓库:git remote -v
关闭同步仓库:git remote rm ssh项目地址
关联仓库:git remote add origin ssh项目地址
状态查询:git status
总体来说:
git init
git remote add origin 项目ssh地址
git clone 项目ssh地址
git add .
git commit -m "随便来个注释"
git pull --rebase origin master
git push -u origin master
Git的复制和粘贴快捷键
- git 的复制:Ctrl + Ins
- git 的粘贴:Shift + Ins
踩坑
如果出现以下报错(windows环境下):
warning: in the working copy of 'day08/ewshop2/css/iconfont.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day08/ewshop2/font_4609259_ek0iicsygfm/demo.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day08/ewshop2/font_4609259_ek0iicsygfm/demo_index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day08/ewshop2/font_4609259_ek0iicsygfm/iconfont.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day08/ewshop2/font_4609259_ek0iicsygfm/iconfont.json', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day10/bookBrothers/css/iconfont.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day10/fontDemo/demo.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day10/fontDemo/demo_index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day10/fontDemo/iconfont.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'day10/fontDemo/iconfont.json', LF will be replaced by CRLF the next time Git touches it
报错原因
这些警告信息是因为你的Git仓库配置中的行结束符(line ending)设置与你的文件系统中的行结束符不一致所导致的。在Windows系统中,通常使用回车加换行(CRLF,
\r\n
)作为行结束符,而在Linux和macOS系统中,则只使用换行符(LF,\n
)作为行结束符。
解决
1.确保Git自动处理行结束符的转换
git config --global core.autocrlf true
2.对某些文件或文件夹有更细粒度的控制,可以创建一个 .gitattributes
文件在你的仓库根目录下,并添加如下规则:
* text=auto
上面这条规则会让Git尝试自动判断哪些文件应该被视为文本文件,并据此应用 core.autocrlf
的设置。
如果希望特定文件不被转换,可以添加如下规则:
*.css binary
这表示 .css
文件应被视为二进制文件,Git将不会尝试转换其行结束符。