git常用记录

一些日常使用记录

常用命令

  1. 切换分支
在git checkout 分支名
  1. 查看分支
git branch -r
git branch -a  //查看所有分支包括本地分支和远程分支
  1. 合并分支
git merge 来源分支
  1. 删除分支
git branch -D 分支名 //删除本地分支
git push origin --delete 分支名 //删除远程分支
  1. 本地同步远程
git fetch  //同步远程最新版本到本地
git remote prune origin //同步远程分支到本地,远程已被删除的分支,本地不再看到
  1. 创建并切换到新分支
git checkout -b 新分支名
然后提交的时候需要输入
git add .
git commit -m'备注信息'
git push --set-upstream origin 新分支名
  1. 暂存代码
git stash
  1. 恢复暂存区内容
git stash pop
  1. 撤回commit
git reset --soft HEAD^
  1. 重命名分支
git branch -m oldBranch newBranch

常见问题

  1. Git 远程仓库名名变更 本地同步 解决方案
    当我们的远程仓库名变更之后,本地想提交代码就会出现错误,所以我们需要将本地和远程重新同步一下
git remote set-url origin 远程仓库地址
git remote -v //查看一下结果
  1. git pull 失败
    出现以下信息:

git常用记录_第1张图片
解决:
解决方案

你可能感兴趣的:(git)