Git 笔记, git reset 撤销

本文详细介绍了Git的reset命令,包括如何使用git reset HEAD <file>撤出暂存区,以及--soft和--hard选项的区别,如何回退到特定版本,并影响提交历史和工作区状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

git reset


1.   git reset HEAD <file>

将 某文件 撤出暂存目录stage

mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ git status 
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   .gitignore
	new file:   new_file_test2.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	new_file_test.txt
执行后:

mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ git reset HEAD .gitignore
Unstaged changes after reset:
M<span style="white-space:pre">	</span>.gitignore
mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ git status 
On branch master
Your branch is up-to-date with 'origin/master'.


Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


<span style="white-space:pre">	</span>new file:   new_file_test2.txt


Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)


<span style="white-space:pre">	</span>modified:   .gitignore


Untracked files:
  (use "git add <file>..." to include in what will be committed)


<span style="white-space:pre">	</span>new_file_test.txt


2. git reset --soft/ --hard <commit hash>

git reset –soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可

 git reset –hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值