search

Home  >  Q&A  >  body text

linux - Git的 checkout 是个本地命令吗?

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

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

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

git checkout -f
git pull

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

PHP中文网PHP中文网2784 days ago715

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 11:26:04

    checkout is a local command

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

    Git can be used without an Internet connection, your understanding is correct

    git checkout -f I tested it and the result is like this

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

    In addition, the git-checkout man manual says this

     -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.
    

    Changed the file, added a file and tested it

    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)
    

    The files that were changed and added to the cache are gone

    reply
    0
  • Cancelreply