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

相关文章
相关标签/搜索