Comments (1)
解密 reset,顺便比较 checkout
概要
git 的思维框架可以看做管理三棵树(树?三个东西也行):HEAD(一个指针,指向该分支最后的一次提交)、Index(暂存区)、Working Directory(工作区)
reset 命令通常是下面的样子
# 没有 [commit](hashID) 则表示最新一次提交
git reset [--soft/--hard] [commit]
它可以看作主要做了这三步:
-
- 移动 HEAD 指向 [commit],若加了 --soft,则就此停止
-
- 将 HEAD 对应的内容复制到 Index,若没有 --hard,则就此停止
-
- 将 Index 的内容复制到 Working Directory
应用
reset 命令可以有以下应用(根据上面步骤看):
- 取消暂存
# 若没有 [path] 则表示取消所有暂存
git reset [path]
- 撤销修改 或 回滚到某一次提交
# 若没有 [commit] 则表示撤销修改,有则表示回滚到该提交
git reset --hard [commit]
- 修改最后一次的提交(重新提交)
# HEAD~ 表示 HEAD 的父提交(上一次提交)
git reset --soft HEAD~; git commit -m 'xxx'
总结
下面的速查表列出了命令对树的影响。 “HEAD” 一列中的 “REF” 表示该命令移动了 HEAD 指向的分支引用,而 “HEAD” 则表示只移动了 HEAD 自身。 特别注意 WD Safe? 一列——如果它标记为 NO,那么运行该命令之前请考虑一下。
-- | HEAD | Index | Workdir | WD Safe? |
---|---|---|---|---|
Commit Level | ||||
reset --soft [commit] | REF | NO | NO | YES |
reset [commit] | REF | YES | NO | YES |
reset --hard [commit] | REF | YES | YES | NO |
checkout | HEAD | YES | YES | YES |
File Level | ||||
reset [commit] | NO | YES | NO | YES |
checkout [commit] | NO | YES | YES | NO |
参考
https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%87%8D%E7%BD%AE%E6%8F%AD%E5%AF%86
from blog.
Related Issues (20)
- DOMContentLoaded 与 load、defer 与 async
- vue-cli使用相关 HOT 2
- webpack相关
- Node相关
- Vue styleguidist相关
- standard-version:版本控制、生成 changelog、打 tag
- element 和 mouseEvent 的位置和尺寸信息相关
- 用class+ts编写vue组件:vue-property-decorator相关
- 尾调用优化:尾递归优化
- 严格模式、替代 eval 的 Function
- TypeScript的模块解析逻辑(类似Node)
- 全屏H5时兼容刘海屏
- css坑!height 使用百分比单位时注意
- in 和 hasOwnProperty
- MutationObserver:监听DOM变化事件(插入、删除、变更等)的观测器
- eject啥意思
- babel插件
- node笔记-全局对象和全局变量
- 动画的12项基本法则
- Git-flow
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.