Git常用指令记录

GIT常用指令

  1. 初始化仓库
git add .
  1. 提交到本地仓库
git commit -m "此处是提交说明"
  1. 查看提交历史
git log --oneline
  1. 切换到历史分支
git checkout xxx
  1. 设置用户名和仓库地址
git config --global user.name "xxx"
git config --global user.email "xxxxxxxxxx"
  1. 查看远程地址
git remote -v
  1. 取消与远程仓库的关联(不是删除仓库内容)
git remote remove xxxx
  1. 添加远程仓库地址
git remote add main url	//url为地址
例子:git remote add main https://github.com/xxx/git_test.git	//将本仓库关联到该地址的main分支
  1. 提交到远程仓库
git push main master	//main为远程仓库分支名,master为本地分支
  1. 查看当前分支名字
git branch --show-current
  1. 查看本地所有分支名字
git branch
  1. 查看远程分支列表
git branch -r
  1. 查看本地所有分支关联的远程分支
git branch -vv
  1. 创建新分支
git branch xxx
  1. 切换分支
git chenckout branch_name
  1. 放弃修改
git restore .         // 放弃所有修改
git restore <file_name>
  1. 暂存修改
    有时候改到一半,需要去历史分支看看,如果直接chenckout会报错的,因为当前工作区有未保存的修改,此时可以暂存,而不是提交
git stash				// 暂存修改
git stash pop		// 取出修改

你可能感兴趣的:(Git常用指令记录)