linux - Git的 checkout 是个本地命令吗?
PHP中文网
PHP中文网 2017-04-17 11:24:04
0
1
731

checkout是切换分支,这个切换仅是在本地所储存的分支分支中切换是吗?

也就是说checkout命令是不需要联网的是吗?

同事写了一个同步脚本为:

git checkout -f
git pull

我理解为:强制checkout到HEAD,然后执行pull,对吗?

PHP中文网
PHP中文网

认证高级PHP讲师

모든 응답(1)
黄舟

checkout是本地命令

git-checkout - Checkout a branch or paths to the working tree

git 不需要联网就可以使用,你的理解是对的

git checkout -f 我测试了下,结果是这样的

rails@1hao:~/tmp/tmp$ git branch 
* hello
  master
rails@1hao:~/tmp/tmp$ git checkout -f 
rails@1hao:~/tmp/tmp$ git branch 
* hello
  master

另外 git-checkout man手册里是这样说的

 -f, --force
           When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

改了文件,加了个文件测试了下

rails@1hao:~/tmp/tmp$ git status
# On branch hello
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   b
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   a
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   c
rails@1hao:~/tmp/tmp$ git checkout -f 
rails@1hao:~/tmp/tmp$ git status 
# On branch hello
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   c
nothing added to commit but untracked files present (use "git add" to track)

那些更改的和添加到缓存区的文件都没有了

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿