git操作命令清单

188 阅读2分钟
操作命令 说明
git config --global user.name/user.email 全局配置用户名和邮件地址
git config --global --list 查看当前用户(global)配置
git config [变量名] 查看具体某个变量的设定
git config --unset [变量名] 删除某项配置
git init [目录] 初始化git仓库,初始成功会在当前目录生成一个.get文件,所有git需要的数据和资源都存放在这个目录中
git add [filename]
git commit -m '说明'
git commit -am '说明'该操作代替上面两步
将文件提交到仓库
git clone [仓库地址] 从现有Git仓库中拷贝项目(类似svn checkout)
git status -s(精简模式short) 查看当前项目状态
git reset HEAD 取消已缓存的内容
git rm
git rm -f(强制删除)
git rm --cached(从缓冲区删除)
git rm -r(递归)
删除文件
git mv 移动/重命名

Git分支操作

  • 创建分支命令
    git branch (branchname)
  • 切换分支
    git checkout (branchname)
    切换分支的时候,Git会用该分支最后提交的快照替换工作目录的内容,所以多个分支不需要多个目录
  • 创建分支并切换到该分支下
    git checkout -b (branchname)
  • 删除分支
    git branch -d (branchname)
  • 合并分支
    git merge (branchname)
    出现冲突,vim filename修改冲突内容提交 git commit -am '解决冲突'
    合并分支只会把其他分支内容合并到当前分支,其他分支内容不变

git查看历史记录

  • git log
    显示历史提交记录信息
  • git log --oneline(简介版本)
  • git log --graph(开启拓扑图查看何时出现分支、合并)
  • git log --reverse(逆向显示日志信息)
  • git log --author=zhangsan(查看指定用户提交日志)
  • git log --oneline --before={1.weeks.age} --after={2020-02-10} --no-merges
    查看三周前且在2月10号之后所有提交,--no-merges隐藏合并提交