远程的仓库可以是github、coding、码云、gitee等等
文章目录
- 前言
- 一 初始设置
- 1.1 安装
- 1.2 其他配置
- 情景1:向远程仓库上传一个文件
- 情景2:将本地的仓库推送到GitHub
- 情景3:回车换行
- 情景4 删除修改commit
- 情景5 一台电脑上使用多个github账户
- git add 多个参数
- 情景7 创建新分支并推送
前言
git要在不同的使用环境中使用,经常实践。有两个很好用的文本网址:
Pro Git廖雪峰的git教程 以及一个学习git基本操作的实践网址,闯关游戏:
learn Git Branching
一 初始设置
1.1 安装
Windows在msysGit下载安装
一定要进行换行符的处理,安装时选择checkout windows-style ,commit unix-style line endings
1.2 其他配置
设置姓名以及邮箱,在~/.gitconfig中有该信息
为了提高输出可读性,设置颜色字体。
git config --global color.ui auto
情景1:向远程仓库上传一个文件
cd ~
ls -a
cd .ssh
ssh-keygen -t rsa
gedit id_rsa.pub #复制公钥到仓库账户
git clone git@项目名称.git --branch develop
git checkout -b lzf
git branch
git status
touch test.md
git add test.md
git config --global user.email 邮箱名字@qq.com
git config --global user.name "name"
git commit -m "how to make a deb"
git checkout develop
git merge lzf
git
情景2:将本地的仓库推送到GitHub
git init
git add codes/
git commit -m "first"
git remote add origin git@github.com:SFUMECJF/program.git
git
情景3:回车换行
基本
CRLF: Carriage-Return Line-Feed的缩写,意思是回车换行,即\r\n;
LF: Line-Feed的缩写,意思是换行,即\n;
CR: Carriage-Return的缩写,回车,即\r;
进阶
当我们敲击回车键(Enter)时,操作系统会插入不可见的字符表示换行,不同的操作系统插入不同
Windows: 插入\r\n,回车换行;
Linux\Unix: 插入\n,换行;
MacOS: 插入\r,回车;
Git
- AutoCRLF
提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf true
提交时转换为LF,检出时不转换
git config --global core.autocrlf input
提交检出均不转换
git config --global core.autocrlf false
2.SafeCRLF
拒绝提交包含混合换行符的文件
git config --global core.safecrlf true
允许提交包含混合换行符的文件
git config --global core.safecrlf false
提交包含混合换行符的文件时给出警告
git
情景4 删除修改commit
查看log ,显示在n行
到达某次commit
git log --pretty=oneline -5
git reset --hard commitId
git
情景5 一台电脑上使用多个github账户
相关链接 自己的仓库永远是全局的,使用http啥的都可以。
其他人的仓库,只需要处理他们自己的仓库,所以使用ssh即可。那么就需要生成不同邮箱的ssh,然后复制公钥到github账户里。
按照上面的操作步骤一步步来就行。很清楚了
大概步骤:
git add 多个参数
git add .
git add *
git add -u
git add
情景7 创建新分支并推送
git push -u origin product:product