Git reset、revert用法

reset

reset是删除之前的提交记录,所有的提交点都会被清除,我们看下执行前后的git log区别

D:\workspace\android>git log
commit 87c1277a57544c53c603b04110e3dde100da8f57 (HEAD -> develop_main)
Author: test 
Date:   Wed Aug 2 10:33:59 2023 +0800

    个人分支第三个提交

commit 5717ed2c4ef46830d77043d5923f8011b42f02cb
Author: test 
Date:   Wed Aug 2 10:13:45 2023 +0800

    个人分支第二个提交

D:\workspace\android>git reset 5717ed2c4ef46830d77043d5923f8011b42f02cb
Unstaged changes after reset:
M      util/Util.kt

D:\workspace\android>git log
commit 5717ed2c4ef46830d77043d5923f8011b42f02cb (HEAD -> develop_main)
Author: test 
Date:   Wed Aug 2 10:13:45 2023 +0800

    个人分支第二个提交

执行完成后发现个人分支第三个提交好像从来没有出现过一样,建议不要使用reset,毕竟会把别人的提交点彻底删除

revert

revert 将指定提交的代码给清除掉,提交记录还存在,相当于添加一个新的提交来恢复到之前旧的提交

D:\workspace\android>git log
commit 5717ed2c4ef46830d77043d5923f8011b42f02cb (HEAD -> develop_main)
Author: test 
Date:   Wed Aug 2 10:13:45 2023 +0800

    个人分支第二个提交

commit 2d7a084fbab7ee94d4c93bf6aaba4882a62bb7c5
Author: test 
Date:   Wed Aug 2 10:13:27 2023 +0800

    个人分支第一个提交
D:\workspace\android>git revert 5717ed2c4ef46830d77043d5923f8011b42f02cb
[develop_main 673c8a4] Revert "个人分支第二个提交"
 1 file changed, 1 insertion(+), 4 deletions(-)

D:\workspace\icvp_android>git log
commit 673c8a414db83db6f4e65d659c054d2648bd05cf (HEAD -> develop_main)
Author: test 
Date:   Wed Aug 2 10:45:49 2023 +0800

    Revert "个人分支第二个提交"

    This reverts commit 5717ed2c4ef46830d77043d5923f8011b42f02cb.

commit 5717ed2c4ef46830d77043d5923f8011b42f02cb
Author: test 
Date:   Wed Aug 2 10:13:45 2023 +0800

    个人分支第二个提交

可以看出执行后出现一条新的提交,这个提交内容就是抹除个人分支第二个提交

你可能感兴趣的:(git,elasticsearch,大数据)