git撤消所有未提交的更改

编程入门 行业动态 更新时间:2024-10-10 19:21:44
本文介绍了git撤消所有未提交的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要撤销自上次提交以来的所有变更。在查看了 git reset --hard 和 git reset --hard HEAD /stackoverflow/questions/7999259/git-how-to-perform-the-tfs-equivalent-of-undo-pending-changes\">此信息。我回应与头现在在18c3773 ...但是当我看看我的本地源所有的文件仍然在那里。

解决方案

  • 这将取消暂存您可能已暂停的所有文件 git add :

    git reset

  • 这将恢复所有本地未提交的更改(应在repo root中执行):

    git checkout。

    您也可以将未提交的更改只还原到特定文件或目录:

    git checkout [some_dir | file.txt]

    $ b b

    另一种方式来恢复所有未提交的更改(更长的类型,但从任何子目录工作):

    git reset --hard HEAD

  • 这将删除所有本地未追踪的文件, / em> git跟踪文件保留:

    git clean -fdx

    警告: -x 还会删除所有忽略的文件!

总结:以下执行命令基本上等同于 git clone 从原始来源(但它不会重新下载任何东西,所以更快):

git reset git checkout。 git clean -fdx

典型的用法是在构建脚本中,请确保您的树是绝对干净的 - 没有任何修改或本地创建的对象文件或构建工件,并且希望使其工作速度非常快,并且不会每次都重新克隆整个存储库。

I'm trying to undo all changes since my last commit. I tried git reset --hard and git reset --hard HEAD after viewing this post. I responds with head is now at 18c3773... but when I look at my local source all the files are still there. What am I missing?

解决方案

  • This will unstage all files you might have staged with git add:

    git reset

  • This will revert all local uncommitted changes (should be executed in repo root):

    git checkout .

    You can also revert uncommitted changes only to particular file or directory:

    git checkout [some_dir|file.txt]

    Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):

    git reset --hard HEAD

  • This will remove all local untracked files, so only git tracked files remain:

    git clean -fdx

    WARNING: -x will also remove all ignored files!

To sum it up: executing commands below is basically equivalent to fresh git clone from original source (but it does not re-download anything, so is much faster):

git reset git checkout . git clean -fdx

Typical usage for this would be in build scripts, when you must make sure that your tree is absolutely clean - does not have any modifications or locally created object files or build artefacts, and you want to make it work very fast and to not re-clone whole repository every single time.

更多推荐

git撤消所有未提交的更改

本文发布于:2023-11-09 07:47:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571773.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!