Git使用笔记

生成rsa key


ssh-keygen -t rsa -b 2048 -C "your_email@example.com"

git配置


git config --global user.name "praglody"    //配置用户名
git config --global user.email "praglody@163.com"    //配置用户email

#禁止自动转换换行符
git config --global core.autocrlf false

#提交时转换为LF,检出时不转换
git config --global core.autocrlf input

#禁止检测文件权限变化
git config --global core.filemode false

#拒绝提交包换混合换行符的文件
git config --global core.safecrlf true


# 开发服务器配置
git config --system core.autocrlf input
git config --system core.filemode false
git config --system core.safecrlf true

分支


#查看分支
git branch -a

#切换分支
git checkout branch_name

#创建并切换分支
git checkout -b branch_name

版本回退



#若文件再工作区,把文件恢复到和当前版本库中一样的状态
git checkout -- file_path

#若文件被添加到暂存区,把文件恢复到和当前版本库中一样的状态
git reset HEAD file_path && git checkout -- file_path
-- 或者
git reset --hard HEAD file_path

#若文件已经提交至本地版本库,但未push到远程,则将版本回退到上个版本
--将代码回退到指定版本,且丢弃这次提交之后的所有变更
git reset --hard HEAD^

--将代码回退到指定版本,且将这次提交之后的所有变更都移动到暂存区
git reset --soft HEAD^

--将代码回退到指定版本,且将这次提交之后的所有变更都移动到工作区
git reset HEAD^

#查看历史版本号
git log --pretty=oneline

远程地址更换后,修改本地仓库的远程地址

git remote set-url origin git@git.coding.net:***/***.git
原文地址:https://www.cnblogs.com/praglody/p/git.html