如何从 Git 的中央存储库更新特定文件夹/文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6138817/
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-10 11:00:27  来源:igfitidea点击:

How to update particular folder/file from central repository in Git?

gitrepository

提问by baluchen

Is there a way to update folder or file alone in Git? I had cloned from central repository and wish to update only specific folder/files.

有没有办法在 Git 中单独更新文件夹或文件?我从中央存储库克隆并希望仅更新特定文件夹/文件。

回答by Abizern

you can use git fetchto update the objects in your local clone, and then you can git checkoutthose particular files.

您可以使用git fetch更新本地克隆中的对象,然后您可以使用git checkout这些特定文件。

For example - if your remote is called origin and you only want to update main.cfrom the master branch you can do this:

例如 - 如果你的远程被称为 origin 并且你只想main.c从主分支更新你可以这样做:

git checkout origin/master main.c

This will update the file in your working directory and add it to the index ready to be committed on your local branch.

这将更新您工作目录中的文件并将其添加到准备在本地分支上提交的索引中。

回答by dunni

No, you can only fetch/pull commits, which will affect the entire repository.

不,您只能获取/拉动提交,这会影响整个存储库。