我如何从一个git回购签出一个文件?
当前回答
我添加这个答案作为做正式签出或一些类似的本地操作的替代方案。假设您可以访问Git提供程序的web界面,您可能能够在给定的提交时直接查看任何文件。例如,在GitHub上,你可以使用这样的东西:
https://github.com/hubotio/hubot/blob/ed25584f/src/adapter.coffee
这里ed25584f是感兴趣的提交的SHA-1散列的前8个字符,后面是源文件的路径。
类似的,在Bitbucket上我们可以尝试:
https://bitbucket.org/cofarrell/stash-browse-code-plugin/src/06befe08
在本例中,我们将提交散列放在源URL的末尾。
其他回答
如果你有一个本地修改的文件(搅乱了git的文件),只需要这样做:
git checkout origin/master filename
Git签出-切换分支或恢复工作树文件,(这里我们什么都不切换,只是覆盖文件 Origin /master -您当前的分支,或者您可以使用特定的修订号,例如:cd0fa799c582e94e59e5b21e872f5ffe2ad0154b, 包含项目主目录路径的文件名(.git目录所在位置) 所以如果你有结构:
“.git
公共/ index . html
public / css / style . css
供应商
composer.lock”
想要重新加载index.html -只需使用public/index.html
在GIT 1.7.2.2中工作
例如,你有一个带有分支branch1和branch32的远程some_remote
所以要签出一个特定的文件,你可以调用这些命令:
git checkout remote/branch path/to/file
举个例子,大概是这样的
git checkout some_remote/branch32 conf/en/myscript.conf
git checkout some_remote/branch1 conf/fr/load.wav
这个检出命令将整个文件结构conf/en和conf/fr复制到当前目录,在这里您调用这些命令(当然,我假设您在之前的某个时候运行了git init)
如果您只需要下载文件,则不需要使用Git签出。
GitHub Mate更容易做到这一点,它是一个Chrome扩展,让你点击文件图标下载它。也是开源的
我没有看到在这里列出的对我有用的东西,所以我将包括它,如果有人在我的情况下。
My situation, I have a remote repository of maybe 10,000 files and I need to build an RPM file for my Linux system. The build of the RPM includes a git clone of everything. All I need is one file to start the RPM build. I can clone the entire source tree which does what I need but it takes an extra two minutes to download all those files when all I need is one. I tried to use the git archive option discussed and I got “fatal: Operation not supported by protocol.” It seems I have to get some sort of archive option enabled on the server and my server is maintained by bureaucratic thugs that seem to enjoy making it difficult to get things done.
最后我进入了bitbucket的网页界面,看到了我需要的一个文件。我右键点击链接下载文件的原始副本,并从弹出的结果中选择“复制快捷方式”。我不能只是下载原始文件,因为我需要自动化操作,而且我的Linux服务器上没有浏览器界面。
为了便于讨论,结果是URL:
https://ourArchive.ourCompany.com/projects/ThisProject/repos/data/raw/foo/bar.spec?at=refs%2Fheads%2FTheBranchOfInterest
我不能直接从bitbucket存储库下载这个文件,因为我需要先登录。经过一番挖掘,我发现这个方法有效: 在Linux上:
echo "myUser:myPass123"| base64
bXlVc2VyOm15UGFzczEyMwo=
curl -H 'Authorization: Basic bXlVc2VyOm15UGFzczEyMwo=' 'https://ourArchive.ourCompany.com/projects/ThisProject/repos/data/raw/foo/bar.spec?at=refs%2Fheads%2FTheBranchOfInterest' > bar.spec
这种组合允许我下载构建其他所有内容所需的一个文件。
我添加这个答案作为做正式签出或一些类似的本地操作的替代方案。假设您可以访问Git提供程序的web界面,您可能能够在给定的提交时直接查看任何文件。例如,在GitHub上,你可以使用这样的东西:
https://github.com/hubotio/hubot/blob/ed25584f/src/adapter.coffee
这里ed25584f是感兴趣的提交的SHA-1散列的前8个字符,后面是源文件的路径。
类似的,在Bitbucket上我们可以尝试:
https://bitbucket.org/cofarrell/stash-browse-code-plugin/src/06befe08
在本例中,我们将提交散列放在源URL的末尾。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 如何在Python中获得所有直接子目录
- 即使模板文件存在,Flask也会引发TemplateNotFound错误
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 如何在Ruby中创建文件
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支