Git 命令行入门2(本地仓库)

125 阅读1分钟

1、重要重要重要

  • git add . 和 git commit -v 最重要的

2、git的6行配置

  • git config --global user.name 你的英文名
  • git config --global user.email 你的邮箱
  • git config --global push.default simple
  • git config --global core.quotepath false
  • git config --global core.editor "code --wait"
  • git config --global core.autocrlf input
  • 运行完这6行配置后,在使用git
  • 注:实在git bash 中运行的git命令行

3、创建

  • git init 会创建 .git目录

4、增加、改变、提交

  • git add +相对路径+文件名 选择将要提交的改动(相对路径:.和*)
  • 通过添加 .gitignore 文件,来添加不需要提交的文件,如:node-modules、.DS-Store、.idea、.vscode
  • git commit -m xxx (字符串) 把代码提交到本地仓库中,用xxx来记录
  • git reset --hard xxxxxx(ID) 返回某个版本,由XXXXXX决定
  • git log 查看当前的几个版本(女朋友)
  • git reflog 查看之前的所有版本(穿越后的自己)

5、创建分支

  • git branch x 基于当前commit的快照,创建一条平行的时间线x
  • git checkout x 切换到分支x
  • git checkout master 切换到master分支
  • git merge x 把分支x的内容合并到master下面
  • git status 和git status -sb 查看当前状态
  • git branch -d x 删除分支x
  • 注意:删除一个文件,如style.css后,也需要git add style.css 和 git commit -v 的操作