我试图撤销自上次提交以来的所有更改。在看完这篇文章后,我尝试了git reset -hard和git reset -hard HEAD。我回复头部现在在18c3773…但当我查看我的本地资源时,所有的文件都还在那里。我错过了什么?
当前回答
还有git stash——它可以“存储”你的本地更改,可以在以后重新应用,也可以在不再需要时删除
更多关于存储的信息
其他回答
国家从一个承诺过渡到新的承诺
0. last commit,i.e. HEAD commit
1. Working tree changes, file/directory deletion,adding,modification.
2. The changes are staged in index
3. Staged changes are committed
状态转换的动作
0->1: manual file/directory operation
1->2: git add .
2->3: git commit -m "xxx"
检查差异
0->1: git diff
0->2: git diff --cached
0->1, and 0->2: git diff HEAD
last last commit->last commit: git diff HEAD^ HEAD
恢复到上次提交
2->1: git reset
1->0: git checkout . #only for tracked files/directories(actions include modifying/deleting tracked files/directories)
1->0: git clean -fdx #only for untracked files/directories(action includes adding new files/directories)
2->1, and 1->0: git reset --hard HEAD
相当于git的克隆,没有重新下载任何东西
git reset && git checkout . && git clean -fdx
另一个选项是取消未提交的更改:
git restore <file>
丢弃工作目录中的更改。
使用以下命令
git remove-changes
git clean -fdx
我要做的是
git add . (adding everything)
git stash
git stash drop
一行代码:git add。少不更事的藏匿物,少不更事的藏匿物掉落
贾斯廷指出的一个更短的版本
Git stash -u && Git stash drop
对于那些到达这里搜索是否可以撤消git clean -f -d的人,通过它在eclipse中创建的文件被删除,
你也可以在UI中使用“restore from local history”为ref: restore from local history进行同样的操作
推荐文章
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- 在Jar文件中运行类
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 如何在Windows命令提示符下运行.sh ?
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 如何从命令行通过mysql运行一个查询?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 如何从命令行在windows中找到mysql数据目录