Git 基础 – 撤销操作

使用 git restore 撤销操作

Git 2.23.0 版引入了一个新命令:git restore. 它基本上是git reset我们刚刚介绍的替代方案。从Git版本2.23.0开始,Git会使用git restore,而不是git reset许多撤消操作。

让我们回溯我们的步骤,并使用git restore而不是撤消事情git reset

使用 git restore 取消暂存文件


git restore --staged  app/code/Yaoli/RemoveSku

git status
On branch yshuq
Your branch is up to date with 'origin/yshuq'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   app/code/Yaoli/RemoveSku/etc/module.xml
        new file:   app/code/Yaoli/RemoveSku/registration.php
        new file:   app/code/Yaoli/RemoveSku/view/frontend/layout/catalog_product_view.xml
        new file:   app/code/Yaoli/RemoveSku/view/frontend/layout/catalog_product_view.xml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   app/design/frontend/ayo/ayo_default/Magento_Catalog/layout/catalog_product_view.xml 

# git restore --staged  app/code/Yaoli/RemoveSku
[root@ip-172-31-25-129 public_html]# git status
On branch yshuq
Your branch is up to date with 'origin/yshuq'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   app/design/frontend/ayo/ayo_default/Magento_Catalog/layout/catalog_product_view.xml 

本次参考:https://git-scm.com/book/en/v2/Git-Basics-Undoing-Things