日常操作
- 添加文件到版本库
git add - 添加单个文件到版本库
git add test.text - 添加某个后缀的文件
git add *.html - 提交版本库文件
git commit -m 备注 - 推入仓库
git push - 从仓库拉取文件
git pull
查看历史状态
- 当前状态
git status - 查看历史记录
git log
撤销修改
- 撤销尚未提交的所有修改
git checkout head . - 撤销尚未提交的单个后缀文件
git checkout head *.后缀
分支
- 查看分支
# 查看本地所有分支 git branch # 查看远程所有分支 git branch -r # 查看本地和远程所有分支 git branch -a - 新建分支
git branch 分支名称 # 以远程分支为基础新建一个分支,并切换到该分支 git checkout -b 分支名称 origin/远程分支 - 切换分支
git checkout 分支名称 - 删除分支
# 删除分支(这个命令如果分支没有被合并会删除失败) git branch -d 分支名称 # 删除分支(这个命令是强制删除) git branch -D 分支名称 # 删除远程已经不存在的分支 git remote prune origin - 合并分支
# 如果发生冲突,就不会自动提交 git merge 指定分支名称 - 重命名分支
# 不会覆盖同名分支 git branch -m 原来的分支名称 新的分支名称 # 会覆盖同名分支 git branch -M 原来的分支名称 新的分支名称 - 在现有分支与指定的远程分支之间建立追踪关系
git branch --set-upstream 分支名称 远程分支名称
克隆
- 克隆项目
git clone 项目的ssh或http地址 # ssh git clone git@github.com:songxiaoQ/test.git # https git clone https://github.com/songxiaoQ/test.git - 克隆指定分支的代码
git clone -b 分支名称 项目的ssh或http地址
基本设置(初始化)
- 全局配置git账号
git config --global user.name "Your Name" git config --global user.email "you@example.com" - 查询已配置git账号
git config --global user.name git config --global user.email - 移除全局配置账号
git config --global --unset user.name git config --global --unset user.email - 生成SSH公钥
ssh-keygen -t rsa -C "you@example.com" - 初始化git版本库
git init
其他命令
-
git里设置大小写敏感。Windows上的Git默认是大小写不敏感的
git config core.ignorecase false