我如何从一个git回购签出一个文件?
当前回答
在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仓库:
首先,你需要克隆git存储库,并给出一个特殊提示——不签出
git clone --no-checkout <git url>
下一步是用下面的命令清除索引中的非暂存文件:
git reset
现在你可以开始拉出你想要修改的文件了:
git checkout origin/master <path to file>
现在,存储库文件夹包含您可以立即开始编辑的文件。编辑完成后,您需要执行简单而熟悉的命令序列。
git add <path to file>
git commit -m <message text>
git push
在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 checkout from-branch-name -- path/to/the/file/you/want
这将不会签出from-branch-name分支。您将停留在您所在的分支上,并且只有该文件将从指定的分支签出。
下面是git-checkout手册的相关部分
git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
When <paths> or --patch are given, git checkout does not switch
branches. It updates the named paths in the working tree from the
index file or from a named <tree-ish> (most often a commit). In
this case, the -b and --track options are meaningless and giving
either of them results in an error. The <tree-ish> argument can be
used to specify a specific tree-ish (i.e. commit, tag or tree) to
update the index for the given paths before updating the working
tree.
向Ariejan de Vroom致敬,他在这篇博客文章中教会了我这些。
是的,你可以通过这个命令下载一个特定的文件
wget -o <DesiredFileName> <Git FilePath>\?token\=<personalGitToken>
例子
wget -o javascript-test-automation.md https://github.com/akashgupta03/awesome-test-automation/blob/master/javascript-test-automation.md\?token\=<githubPersonalTone>
Git checkout branch_or_version——path/file
示例:git checkout HEAD——main.c
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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拉另一个分支