Git: How to update/checkout a single file from remote origin master?

后端 未结 7 945
长发绾君心
长发绾君心 2020-12-12 08:41

The scenario:

  1. I make some changes in a single file locally and run git add, git commit and git push
  2. The file is
7条回答
  •  悲哀的现实
    2020-12-12 09:40

    With Git 2.23 (August 2019) and the new (still experimental) command git restore, seen in "How to reset all files from working directory but not from staging area?", that would be:

    git fetch
    git restore -s origin/master -- path/to/file
    

    The idea is: git restore only deals with files, not files and branches as git checkout does.
    See "Confused by git checkout": that is where git switch comes in)


    codersam adds in the comments:

    in my case I wanted to get the data from my upstream (from which I forked).
    So just changed to:

    git restore -s upstream/master -- path/to/file
    

提交回复
热议问题