你好,我对这两个命令的区别很感兴趣。当他们在这里介绍时:https://www.atlassian.com/git/tutorials/undoing-changes
看起来 git reset --hard
命令也会将暂存区和工作目录设置为与最新提交相匹配,但最后他们说 git reset --hard
不会改变当前的工作目录。因此,我在这里非常困惑,请有人澄清一下吗?
你好,我对这两个命令的区别很感兴趣。当他们在这里介绍时:https://www.atlassian.com/git/tutorials/undoing-changes
看起来 git reset --hard
命令也会将暂存区和工作目录设置为与最新提交相匹配,但最后他们说 git reset --hard
不会改变当前的工作目录。因此,我在这里非常困惑,请有人澄清一下吗?
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.
有关重置和清除及其--选项的更多内容
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