git笔记-常用命令

本文是廖雪峰的git教程笔记

1、 git add and git commit

  • git add <file>可以执行多次
  • 然后git commit -m "discription"一次提交多个已通过add添加到缓存区的文件

2、版本回退(commit里面的)

  • git reset --hard HEAD^回到上一个版本
  • git reset --hard HEAD~100回到上100个版本
  • git log --pretty=oneline查找提交历史,以便回退到某个版本
  • git reflog查找命令历史,git reset --hard <commit id>回到未来版本

3、撤销修改(未commit的)

  • git checkout -- <file>只在工作区做过修改时,直接丢弃工作区的修改
  • git reset HEAD <file>将修改add进暂存区时,首先撤销放在暂存区的修改,然后再用第一步丢弃工作区的修改

4、删除文件

  • 首先,rm <file>或者手动删掉
  • 然后,git rm <file>git commit -m "discription"从版本库中删除文件
  • 如果误删文件,git checkout -- <file>恢复

5、创建和合并分支

  • git branch 查看分支
  • git checkout -b <branch> 创建分支并切换分支
    • 等同于git branch <branch> + git checkout <branch>
  • git merge <branch> 合并分支到当前分支(git merge --no-ff -m "discription" <branch>禁用快进模式)
  • git branch -d <branch> 删除分支
  • git log --graph --pretty=oneline --abbrev-commit 查看分支合并图
  • git stash储藏工作现场
  • git stash list查看工作现场
  • git stash pop恢复工作现场
原文地址:https://www.cnblogs.com/u14e/p/5939266.html