从 git 更新单个文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27912411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:41:12  来源:igfitidea点击:

Update a single file from git

git

提问by Arjan

I would like to update a specific file in a repository that I use.

我想更新我使用的存储库中的特定文件。

Basically I have repo X, which has N files.

基本上我有 repo X,它有 N 个文件。

For one test, I need to have the latest and greatest of a specific file, since my application is already loaded, I can't just download the whole project again.

对于一项测试,我需要拥有最新和最大的特定文件,因为我的应用程序已经加载,我不能再次下载整个项目。

Is there a way to tell git to get from the repo, the latest and greatest version of just a specific file, without sync the whole repo/project?

有没有办法告诉 git 从 repo 中获取,只是一个特定文件的最新和最好的版本,而不同步整个 repo/项目?

I see that many uses the archive option of git, which to me seems a bit an overkill...I need to send a command to archive, and then another to unarchive on my local directory; while I would like that git would simply look at the repo, and if there are changes only to that specific file, it will update it.

我看到很多人使用 git 的存档选项,对我来说这似乎有点矫枉过正……我需要发送一个命令来存档,然后再发送一个命令在我的本地目录中取消存档;虽然我希望 git 只查看 repo,如果仅对该特定文件进行了更改,它将更新它。

How do you do that? I can't see in Git manual a way to specify a file in the repo. I use regular git from console, no UI nor Github.

你是怎样做的?我在 Git 手册中看不到在 repo 中指定文件的方法。我从控制台使用常规 git,没有 UI 或 Github。

回答by Arjan

First make sure you have the latest and greatest version available in your local git repo:

首先确保您的本地 git 存储库中有最新和最好的版本:

git fetch origin

Then retrieve the one specific file you're looking for

然后检索您要查找的特定文件

git checkout origin/master -- path/to/the/file

The --tells gitthat all other arguments are files, not parameters.

--通知git所有其他参数是文件,没有参数。