Ale*_*ang 20 git git-reset git-clean
嗨,我很好奇这两个命令之间的区别.当他们在这里介绍时:https://www.atlassian.com/git/tutorials/undoing-changes
看起来像git reset --hard也设置了staging和工作目录以匹配最新的提交,但最后他们说git reset --hard不会改变当前的工作目录.所以我在这里很困惑,有人可以澄清一下吗?
zee*_*zee 11
他们做了两件不同的事情.比方说,你做了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
Run Code Online (Sandbox Code Playgroud)
选择要回滚的提交,如下所示:
git reset --hard 73b9363
Run Code Online (Sandbox Code Playgroud)
重置HEAD后,所有未提交的更改/文件都将消失.
至于git clean.下面是git-docs如何描述它.
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.
Run Code Online (Sandbox Code Playgroud)
有关重置与清洁及其 - 选项的更多信息
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4752 次 |
最近记录: |