1、git 修改了文件,未add时,撤销
git checkout -- <file>
其实git里面都有明显的提示,如下图

2、git add了,但是还没有commit
git reset HEAD <file>
同样,这个在git里面,还是有提示的。看下图

3、git commit 后,如何撤销。
git reset HEAD^
这个,好像git上没有提示。我们看一下执行后会是什么样子。从下图中看出,变成了和未add时一样的。然后用git checkout -- <file> 撤销回来。

4、git 在合并时,发生冲突了,不想合并了。
git merge --abort
5、git在合并后,没有冲突,就是不想合并了。
git reset HEAD^
跟撤销 commit 一样,执行后,在用git checkout -- <file> 撤销回来。
6、git 暂时保存一下修改的文件
git stash // 暂存命名,执行后,就跟没有修改任何东西一样,你可以切换到别的分支。
git stash pop // 恢复暂存命令,执行后,就恢复了你刚才暂存的。
网友评论