- 工作区 working directory
- 暂存区 staging area
- 本地版本库 local repository
git checkout .
git 2.23版本git checkout
命令 拆分为git switch
和git restore
两个命令,更直观了git reset --hard HEAD
git clean -df
`git checkout .` 只对工作区内跟踪过的文件有作用
`git restore --staged .` 可把暂存区内文件回退到工作区
`git reset --head HEAD` 对工作区和暂存区的跟踪过的文件都起作用 对未跟踪的文件不起作用
`git clean -df` 只对工作区内未跟踪的文件生效
所以 彻底恢复工作树的命令为
git reset --hard && git clean -f -d
.gitignore
只对未跟踪的文件起作用
如果文件已经跟踪过则需要移除
- 添加文件到 .gitignore
- 执行
git rm --cached 文件
并提交 - 重新创建这个文件就不会被跟踪了
git reset --soft commit id
回退到指定版本, 变动的文件会保留在工作区和暂存区git reset --hard commit id
回退到指定版本, 变动的文件不会保留git reset --mixed commit id
回退到指定版本, 变动的文件会保留在工作区
--soft
--hard
--mixed
git reset --hard commit id
回退到指定版本, 这个版本之后的记录都会删除 可以用git reflog
查看删除过的记录git revert commit id
撤回某次提交
git merge branch
git rebase branch