git学习使用
学习Git命令的网站
https://learngitbranching.js.org/
https://github.com/pcottle/learnGitBranching
Win环境下载Git
git常用配置
# 设置用户名和邮箱
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
# 替换所有
git config --global url.ssh://[email protected]/.insteadOf https://github.com/
# 避免git push时候每次都要密码
git config --global credential.helper wincred
# 解决git status不能显示中文
git config --global core.quotepath false
# 解决git log不能显示中文
git config --global i18n.commitencoding utf-8 #该命令表示提交命令的时候使用utf-8编码集提交
git config --global i18n.logoutputencoding utf-8 #该命令表示日志输出时使用utf-8编码集显示
export LESSCHARSET=utf-8 #设置LESS字符集为utf-8
# windows电脑设置:提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf true
# linux/mac电脑设置:提交时转换为LF,检出时不转换
git config --global core.autocrlf input
# windows开发,只在windows上运行:提交检出均不转换
git config --global core.autocrlf false
其他
# git网速问题,拉取或推送超时
git config --global http.postBuffer 1048576000
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999 #单位 秒
git文件和版本管理
git刷新忽略文件
# 重置所有缓存(注意后面有个.)
git rm -r --cached .
# 重新添加(注意后面有个.)
git add .
git 对比
用git diff HEAD – readme.txt命令可以查看工作区和版本库里面最新版本的区别
git diff <commit_id> -- <file>
git撤销修改
git add之后,但是还没有git commit的文件——工作区文件撤销修改
git checkout -- <file>
git add并且git commit的文件——暂存区文件撤销修改
git reset HEAD <file>
git删除文件
git rm <file>
git commit -m "xxx"
git回滚到某个提交
用git log
可以查看提交历史,以便确定要回退到哪个版本
用git reflog
查看命令历史,以便确定要回到未来的哪个版本
git reset --hard <commit_id>
git push origin HEAD --force
git远程管理
git 将本地项目与远程项目相关联
git init
git remote add origin <git_address>
git pull origin master
git add <file>
git commit -m 'xxx'
git push -u origin master
git克隆指定分支
git clone <git_address> -b <branch> # 克隆并checkout到指定分支
git分支管理
git创建与合并分支
git checkout -b <name>
git add xxx,git commit -m “xxx”,开发若干时间后…
git checkout master
git merge <name>
git branch -d <name>