git checkout master               # first get back to master
git checkout experiment -- app.js # then copy the version of app.js 
                                  # from branch "experiment"
另请参见git如何撤消对一个文件的更改?
更新2019年8月,Git 2.23
使用new git switch和git restore命令,将是:
git switch master
git restore -s experiment -- app.js
默认情况下,仅还原工作树。
如果您还想更新索引(意味着还原文件内容,并通过一个命令将其添加到索引中):
git restore -s experiment --staged --worktree -- app.js
# shorter:
git restore -s experiment -WS -- app.js
正如雅库布·纳伦斯基(JakubNarębski)在评论中提到的那样:
git show experiment:path/to/app.js > path/to/app.js
除SO问题“ 如何从Git中的特定修订版本检索单个文件? ”中详细介绍的之外,该方法同样适用,您需要使用来自仓库的根目录的完整路径。
因此,Jakub在他的示例中使用了path / to / app.js。
正如Frosty在评论中提到的那样:
  您只会得到app.js的最新状态
但是,对于git checkout或git show,您实际上可以引用所需的任何修订版,如SO问题“ git gui中文件的git checkout修订版 ”所示:
$ git show $REVISION:$FILENAME
$ git checkout $REVISION -- $FILENAME
相同的是$ FILENAME是版本文件的完整路径。
$REVISION可以如下所示git rev-parse:
experiment@{yesterday}:app.js # app.js as it was yesterday 
experiment^:app.js            # app.js on the first commit parent
experiment@{2}:app.js         # app.js two commits ago
等等。
schmijos添加了评论:
  您也可以从隐藏处执行此操作: 
git checkout stash -- app.js
  
  如果您正在两个分支上并且不想提交,这将非常有用。