他们做两件不同的事情。假设你做了GIT PULL 然后开始编辑一些文件并且可能已经添加并提交了这些更改到被推送...然后由于某种原因你决定放弃对给定文件所做的所有更改并回到较早的状态。在这种情况下你会这样做
$ git reflog
... snip ...
cf42fa2... HEAD@{0}: commit: fixed misc bugs
~
~
cf42fa2... HEAD@{84}: commit: fixed params for .....
73b9363... HEAD@{85}: commit: Don't symlink to themes on deployment.
547cc1b... HEAD@{86}: commit: Deploy to effectif.com web server.
1dc3298... HEAD@{87}: commit: Updated the theme.
18c3f51... HEAD@{88}: commit: Verify with Google webmaster tools.
26fbb9c... HEAD@{89}: checkout: moving to effectif
选择要回滚的提交,如下所示:
git reset --hard 73b9363
重置 HEAD 后,所有更改/暂存文件都将消失。
至于 git clean 。以下是git-scm.com 的描述方式。
DESCRIPTION
Cleans the working tree by recursively removing files that
are not under version control, starting from the current directory.
Normally, only files unknown to Git are removed, but if the -x
option is specified, ignored files are also removed. This
can, for example, be useful to remove all build products.
If any optional <path>... arguments are given, only those paths are affected.
更多关于 reset vs clean 以及它们的 --options
lnydex99uhc:~ user$ git reset -h
usage: git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
or: git reset [-q] <tree-ish> [--] <paths>...
or: git reset --patch [<tree-ish>] [--] [<paths>...]
-q, --quiet be quiet, only report errors
--mixed reset HEAD and index
--soft reset only HEAD
--hard reset HEAD, index and working tree
--merge reset HEAD, index and working tree
--keep reset HEAD but keep local changes
-p, --patch select hunks interactively
VS
lnydex99uhc:~ user$ git clean -h
usage: git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>...
-q, --quiet do not print names of files removed
-n, --dry-run dry run
-f, --force force
-i, --interactive interactive cleaning
-d remove whole directories
-e, --exclude <pattern>
add <pattern> to ignore rules
-x remove ignored files, too
-X remove only ignored files