git 取消修改:修改了一些文件,可是並無commit

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

    git reset
  • 撤消對文件的修改

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

    git checkout .

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

    git checkout [some_dir|file.txt]

    取消暫存的文件能夠使用以下方法(指那些已經使用git add命令的)spa

  • Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):雖然在調用時加上 --hard 選項能夠令 git reset 成爲一個危險的命令(譯註:可能致使工做目錄中全部當前進度丟失!),但本例中工做目錄內的文件並不會被修改。 不加選項地調用git reset 並不危險 — 它只會修改暫存區域。code

  • git reset --hard HEAD
  • This will remove all local untracked files, so only git tracked files remain:ip

    git clean -fdx

    WARNING: -x will also remove all ignored files!rem


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):get

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.it

相關文章
相關標籤/搜索