git revert 和reset的区别

来源:互联网 发布:python初学者看什么书 编辑:程序博客网 时间:2024/03/29 21:35
这里讲一下git revert和git reset的区别:

git revert 是撤销某次操作,此次操作之前的commit都会被保留

git reset 是撤销某次提交,但是此次之后的修改都会被退回到暂存区

具体一个例子,假设有三个commit, git st:

commit3: add test3.c

commit2: add test2.c

commit1: add test1.c

当执行git revert HEAD~1时, commit2被撤销了

git log可以看到:

commit1:add test1.c

commit3:add test3.c

git st 没有任何变化

如果换做执行git reset --soft(默认) HEAD~1后,运行git log

commit2: add test2.c

commit1: add test1.c

运行git st, 则test3.c处于暂存区,准备提交。

如果换做执行git reset --hard HEAD~1后,

显示:HEAD is now at commit2,运行git log

commit2: add test2.c

commit1: add test1.c

运行git st, 没有任何变化
原创粉丝点击