git-13_reset last commit

Reset command note:
Reset 命令有3种方式:

1)	git reset –mixed #默认方式,不带任何参数的git reset 即为这种方式, 他回退到某个版本,只保留源码,回退comit和index信息。
2)	git reset –soft #回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可。
3)	git reset –hard #默认方式彻底回退到某个版本,本地源码也回退到上一版本。
4)	example:
git reset HEAD^    #回退所有内容到上一版本
git reset HEAD^   a.c #回退a.c到上一版本
git reset --soft HEAD~3   #向前回退到第三个版本
git reset --hard   #将本地分支恢复到和remote一样
git reset 039399 #恢复到指定版本

Drop some commit content

$git reset –hard $SHA     #SHA—the head to be restore, be careful to use it.

Scenario: after commit, you found some files are wrongly committed, you want to redo last commit, and also want to keep the changed files.

$git log #find the commit SHA1 before last commit  $last_sha1
$git reset $last_sha1 #After this command, you can see what you commit last time become uncommited
$git status # you can see all your changes for last commit, then you do commit again.
发布了38 篇原创文章 · 获赞 3 · 访问量 6671

猜你喜欢

转载自blog.csdn.net/zhanghuanhuanzhh/article/details/88721126