git基础

73 阅读1分钟

全局配置

git config --list --env[system,global,local]
比如设置我们的用户名和邮箱

  • git config --global user.name 'xx'
  • git config --global user.email 'yy'

暂存区管理

  • git add . 修改后的文件添加到暂存区
  • git rm fileName 删除文件
  • git restore fileName 恢复文件
  • git checkout fileName 把工作区的的文件变化撤销
  • git reset HEAD fileName 把file移除暂存区
  • git reset --hard HEAD~N 把commit回滚前N个记录
  • git reset --soft HEAD
  • git diff --cached 查看暂存区和head的变化
  • git diff --[fileName] 查看工作区和head的变化

管理记录

  • git log --n[num] --oneline[精简模式] 查看记录
  • git reflog 可以查看历史记录
  • git commit -amend 对上一次commit message 进行修改

分支管理

  • git branch -v 查看分支
  • git branch -d 删除分支
  • git branch name 创建分支
  • git checkout -b[创建分支] name commit-hash 基于commit创建分支

remote管理

git remote -v git remote add name url git remote set-url name url

get rebase [变基] -i [target-commit-hash]-1

rebase一般用来改变commit,千万别再集成分支上操作。

image.png

  • r 对message进行重写
  • s 进行合并

git revert

git revert -n commit-hash 对改次commit进行一个回滚补丁操作,不会丢失其他的commit。