5

git进阶(撤销pull、撤销merge、撤销add)

 2 years ago
source link: https://segmentfault.com/a/1190000041004054
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

git进阶(撤销pull、撤销merge、撤销add)

1、撤销本次pull

git reflog

image-20211123115003360

reset到某个版本

git reset --hard 91ae6ad

image-20211123115138013

2、撤销本次merge

如果merge了其他分支代码造成了大量的冲突 想撤销本次merge如果操作

image-20211123121252778

1、使用上面的reset命令撤销到上一个提交版本

2、执行以下命令直接撤销了本地合并

git merge --abort

3、git log高阶用法

查看每次提交的文件修改列表,和分支变化的图形信息

git log --name-status --oneline --graph

image-20211123142821089

普通查询用法

git log

image-20211123142912632

4、git stash

在平时开发中,如果本地分支开发了一部分,但需要切换分支,或者拉取代码,那么在如何不提交修改的前提下,完成pull或者分支切换呢?

git stash 可以将当前工作状态(WIP,work in progress)临时存放在 stash 列表中,待 pull / merge 操作完成后,再从 stash 中重新应用这些修改。

-u 参数表明新增的文件也一起 stash

git stash save -u 'message'

\# 查看 stash 列表中已暂存了多少 WIP

git stash list

\# 恢复上一次的 WIP 状态,并从列表中移除

git stash pop

image-20211123143742546

image-20211123143942657

5、如何撤销修改

1、撤销新建文件或者目录时使用checkout是不生效的

. 表示当前目录及所有子目录中的文件

git clean -fd .

image-20211123144851627

撤销指定文件或者目录

git clean -fd 文件或目录

image-20211123145140777

2、撤销本地update代码修改

git checkout .

这个很常用不再过多赘述


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK