使用“git checkout”时,我对这两个选项感到有点困惑
我一直用git checkout -- .
清除我的工作目录。
但今天当我打字时git checkout - .
因为失误。我发现 git 没有错误警报。
我读过git文档,也不知道这是什么-
选项确实如此。这很难用谷歌搜索。
那么请问有人对此有任何想法吗?
使用时git checkout
, 您可以使用-
作为简写@{-1}
.
From man git-checkout
(强调第二段):
<branch>
Branch to checkout; if it refers to a branch (i.e., a name that, when
prepended with "refs/heads/", is a valid ref), then that branch is checked
out. Otherwise, if it refers to a valid commit, your HEAD becomes
"detached" and you are no longer on any branch (see below for details).
As a special case, the "@{-N}" syntax for the N-th last branch/commit
checks out branches (instead of detaching). You may also specify - which is
synonymous with "@{-1}".
通过在分支中创建文件来在空存储库中尝试此操作master
,在另一个分支中修改它,并使用checkout -
来自大师:
$ git init
Initialized empty Git repository in workspace/git-test/.git/
git:(master) $ echo a > a
git:(master*) $ git add a
git:(master*) $ git commit
[master (root-commit) 8433343] Add a to master
1 file changed, 1 insertion(+)
create mode 100644 a
git:(master) $ git checkout -b other
Switched to a new branch 'other'
git:(other) $ echo b > a
git:(other*) $ git add a
git:(other*) $ git commit
[other be2298f] Replace a by b
1 file changed, 1 insertion(+), 1 deletion(-)
git:(other) $ git checkout -
Switched to branch 'master'
git:(master) $ git checkout -- . # no changes (no * next to master in the line below)
git:(master) $ git checkout - . # checking out files from alternate branch 'other'
git:(master*) $ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a
git:(master*) $ cat a
b
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)