git reset,git restore and git revert
git-reset - Reset current HEAD to the specified state
git-restore - Restore working tree files
git-revert - Revert some existing commits
git-reset - Reset current HEAD to the specified state
git-restore - Restore working tree files
git-revert - Revert some existing commits
其作用是文件在工作区的修改全部撤销,这里有两种情况:
一种是文件自修改后还没有被放到暂存区,撤销修改就回到和版本库一模一样的状态;
一种是文件已经添加到暂存区后,又作了修改,撤销修改就回到添加到暂存区后的状态。
删除文件,一种是从工作区(Workspace)手动删除,另一种是用命令删除 。如果文件还是未跟踪状态,直接删除就可以了。否则还需要清除暂存区(Index / Stage)改变,提交至仓库区(Repository)(或版本区),最终同步至远程仓库(Repository)。
主要代码如下:
1 | |