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:彻底回退到某个版本,本地的源码也会变为上一个版本的内容