从“git pull”中排除特定文件

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

Exclude specific files from 'git pull'

gitgitignorepull

提问by Chris Barnhill

I have a production git repo that I only pull changes from the main repo into; I never change this repo or do commits/pushes from here. I recently accidentally pushed some untracked (at least I thought they were) image files to the main repo from my local dev repo. Now when I try to pull the latest from the main repo, git reports an error regarding overwriting the exiting image file with the file from the main repo. I don't even want this file from the repo (it's located in a ,gitignored directory on the production repo)

我有一个生产 git 存储库,我只将更改从主存储库拉入;我从不更改此 repo 或从这里提交/推送。我最近不小心将一些未跟踪的(至少我认为是)图像文件从我的本地开发仓库推送到主仓库。现在,当我尝试从主存储库中提取最新版本时,git 报告了一个关于用主存储库中的文件覆盖现有图像文件的错误。我什至不想要 repo 中的这个文件(它位于生产 repo 的 ,gitignored 目录中)

How can I a) get rid of these unwanted image files in my main repo, or b) exclude these files from my git pull?

我怎样才能 a) 在我的主存储库中删除这些不需要的图像文件,或者 b) 从我的 git pull 中排除这些文件?

回答by Eduardo Cuomo

This allowed me to tell git to ignore a specific file, even though it was already part of a project. All changes I make to it will be ignored:

这让我可以告诉 git 忽略特定文件,即使它已经是项目的一部分。我对它所做的所有更改都将被忽略:

git update-index --assume-unchanged Localization/el-GR.js

Source: http://codethug.com/2013/09/20/4-ways-to-ignore-files-with-git/

来源:http: //codethug.com/2013/09/20/4-ways-to-ignore-files-with-git/

回答by kwarunek

git pullis equivalent (almost) to git fetch && git merge. You just have to invoke fetch and than merge only specific files - tutorial.

git pull相当于(几乎)到git fetch && git merge. 您只需要调用 fetch 而不是仅合并特定文件 -教程