Git常用命令及原理

git工作模式

git基本命令

  1. #把内容输入到一个文件
  2. echo "xxxx" > xxxx 
  3. #把工作空间的某个文件添加到cache
  4. git add  xxxx
  5. #把工作空间的所有内容添加到cache
  6. git add -A
  7. #把cache当中的某个文件提交到本地库
  8. git commit -m "xxxx"
  9. #all
  10. git commit -am "xxxx"
  11. #cache ---->work file恢复一个文件  file1 file2 恢复两个文件  .恢复所有文件
  12. git checkout readme.txt 
  13. #git状态查询
  14. git status
  15. #查看不同的地方 默认查看工作区和cache
  16. #git diff --cached   比较cache和Repository
  17. #git diff HEAD 工作区和最新的Resository
  18. #git diff commit-id 工作区和制定的repository
  19. #git diff --cached commit-id
  20. #git diff --commit-id commit-id
  21. git diff 
  22. #reset 顾名思义   (HEAD~100)
  23. git reset HEAD^
  24. #git的日志
  25. git log git log --pretty=oneline
  26. #oh my pretty pretty boy i love you 
  27. git reflog  查看历史命令
  28. #git rm --cached file_path
  29. git rm 
  30. git mv
  31. #远程仓库的克隆岛本地库
  32. git clone
  33. #关联远程仓库
  34. git remote add
  35. #推送到远程仓库
  36. git push
  37. #拉取远程仓库的内容
  38. git pull
  39. #查看当前分支 -a查看所有分支 -av 查看所有分支的信息 -avv 查看所有分支的信息和关系
  40. git branch
  41. #创建一个分支 基于当前分支创建分支
  42. git branch  xxx
  43. #基于oldType创建分支
  44. git branch newBranch oldType
  45. #切换分支
  46. git checkout 分支的名字
  47. #删除分支
  48. git branch -d   xxx
  49. #查看文件内容
  50. git cat-file -p  commitid
  51. #查看对象类型 blob commit tree
  52. git cat-file -t commitid

 

github使用ssh添加本地仓库到gitHub

  1. $ ssh-keygen -t rsa -C "email" //public key for push
  1.  git remote add nickName gitUrl // conn remote
  1. git push -u remoteBranch localBranch

git原理

git有4种对象

  1. Blob 对象
存储的是文件内容,压缩的
文件名字是根据内容算出的一个hash值

2tree对象

blob对象
子tree对象

3commit对象

作者提交者注释
指向一个 tree 的指针

首次提交,提交一个简单的文件 a.txt ,commit 之后如上图

生成了 3 个对象,一个 commit 对象,一个 tree 对象,一个 blob 对象。图上蓝底是 commit 对象,灰底的是 tree 对象,白底的是 blob 对象,每个对象节点的标题是对象的 key (SHA 摘要)缩略表示。 对于 commit 对象,tree 内容表示这个 commit 对应根目录的 tree 对象,parent 表示父 commit 节点,通常commit 只有一个父节点,也可能没有(首次提交时 parent 为空),也可能有多个(合并节点),commit 对象还保存了 commit message 等信息。 对于 tree 对象,里面的内容包含了文件名,文件对应的 blob 对象的 key,或者是目录名和目录对应 tree 对象的 key。 对于 blob 对象,表示一个实际文件对象的内容,但不包括文件名,文件名是在 tree 对象里存的。

扫描二维码关注公众号,回复: 5659327 查看本文章

通过 git log 命令获取最新 commit 的 key

通过 git cat-file -p <object key> 获取 key 对应 object 的内容,根据 object 里的内容,继续探索,就可以访问到所有关联 object.

由此git是以元数据来存储,相对于svn的整个文件是基于分布式的,这是两者最大的不同,切换版本时是切换指针来进行切换,所以速度比svn快很多

猜你喜欢

转载自blog.csdn.net/weixin_41934671/article/details/84726323
今日推荐