本文翻译自:Git: How to update/checkout a single file from remote origin master?

The scenario: 场景:

  1. I make some changes in a single file locally and run git add , git commit and git push 我在本地单个文件中进行了一些更改并运行git addgit commitgit push
  2. The file is pushed to the remote origin master repository 该文件被推送到远程源主存储库
  3. I have another local repository that is deployed via Capistrano with the "remote_cache" method from that remote repository 我有另一个本地存储库,通过Capistrano与该远程存储库中的“remote_cache”方法一起部署
  4. Now I don't want to deploy the whole application but just update/checkout that single file. 现在我不想部署整个应用程序,只需更新/签出该单个文件。

Please, is this somehow possible with git? 拜托,这对git来说有点可能吗? I wasn't able to find anything that would work nor was I able to figure it out. 我无法找到任何有用的东西,也无法找到它。 With SVN I just did svn up file and voila. 使用SVN我只是做svn up file和瞧。

I'll be glad for any help, thanks! 我会很高兴得到任何帮助,谢谢!


#1楼

参考:https://stackoom.com/question/DzRr/Git-如何从远程源主服务器更新-签出单个文件


#2楼

Or git stash (if you have changes) on the branch you're on, checkout master, pull for the latest changes, grab that file to your desktop (or the entire app). 或者你正在使用的分支上的git stash(如果你有更改),checkout master,拉取最新的更改,将该文件抓取到你的桌面(或整个应用程序)。 Checkout the branch you were on. 检查你所在的分行。 Git stash apply back to the state you were at, then fix the changes manually or drag it replacing the file. Git stash应用回您所处的状态,然后手动修复更改或拖动替换文件。

This way is not sooooo cool but it def works if you guys can't figure anything else out. 这种方式并不太酷,但如果你们不能解决任何问题,那么def就可以了。


#3楼

git archive --format=zip --remote=ssh://<user>@<host>/repos/<repo name> <tag or HEAD> <filename> > <output file name>.zip

#4楼

What you can do is: 你能做的是:

  1. Update your local git repo: 更新您当地的git仓库:

    git fetch

  2. Build a local branch and checkout on it: 建立一个本地分支并结帐:

    git branch pouet && git checkout pouet

  3. Apply the commit you want on this branch: 在此分支上应用您想要的提交:

    git cherry-pick abcdefabcdef

    (abcdefabcdef is the sha1 of the commit you want to apply) (abcdefabcdef是您要应用的提交的sha1)


#5楼

It is possible to do (in the deployed repository) 可以这样做(在已部署的存储库中)

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

The fetch will download all the recent changes, but it will not put it in your current checked out code (working area). 获取将下载所有最近的更改,但它不会将其放在当前检出的代码(工作区域)中。

The checkout will update the working tree with the particular file from the downloaded changes ( origin/master ). 结帐将使用下载的更改( origin/master )中的特定文件更新工作树。

At least this works for me for those little small typo fixes, where it feels weird to create a branch etc just to change one word in a file. 至少这对我来说对于那些小小的错字修复,在创建分支等只是为了改变文件中的一个单词感觉很奇怪。


#6楼

I think I have found an easy hack out. 我想我已经找到了一个简单的黑客。

Delete the file that you have on the local repository (the file that you want updated from the latest commit in the remote server) 删除本地存储库上的文件(要从远程服务器中的最新提交更新的文件)

And then do a git pull 然后做一个git pull

Because the file is deleted, there will be no conflict 由于文件已删除,因此不会发生冲突

Git:如何从远程源主服务器更新/签出单个文件?相关推荐

  1. 如何仅从git存储库中稀疏签出单个文件?

    如何从git仓库中检出一个文件? #1楼 git checkout branch_or_version-路径/文件 示例: git checkout HEAD -- main.c #2楼 如果您已经有 ...

  2. 集群——双主双从时,从服务器只同步一台主服务器数据

    设置好两台从服务器后,在设置两台从服务器,其中第一台从服务器用的备份是之前的,当手动恢复数据后,数据不能同步到后面的数据,于是,我清除数据库,打算从新做, # systemctl stop mysql ...

  3. 远程源已存在于“ git push”到新存储库中

    我的项目在GitHub上的某个位置git@github.com:myname/oldrep.git . 现在,我想将所有代码推送到其他位置的新存储库git@github.com:newname/new ...

  4. git 从远程服务器更新本地项目

    从远程服务器上更新别人上传的文件 1.使用git fetch更新,相当于是从远程获取最新版本到本地,不会自动merge git fetch origin master git log -p maste ...

  5. git 从远程主服务器当中创建新分支

    现有版本; h20, h28,h26,i8 h28,h26,i8是从H20下面创建的. 需求: 从H28下面创建新分支继续开发. 思路: 所有代码均是放置到H20上仓库当中,首先下载H20完整仓库,也 ...

  6. 【git与github交互之主分支和次分支切换、合并等】

    文章目录 git与github交互分支切换 1. 单个账号分支创建合并测试 2. 作为项目管理者在gihub页面端对成员提交代码审核并合并 3. 多人协作开发逻辑流程 git与github交互分支切换 ...

  7. Git和GitHub学习笔记 V2.0(更新中...)

    文章目录 1. 什么是Git? 2. 为什么要使用Git? 3. Git和Svn的区别 4. Git的历史 5. 版本控制工具应该具备哪些功能 6. 安装Git 7. Git的三区和三种状态 8. G ...

  8. linux 日志主服务器 syslog

    syslog日志服务 syslog日志的主要用途是系统审计,监测追踪和分析统计,syslog是一个综合的日志记录系统,它主要的功能是方便日志管理和分类存放日志 日志syslog的功能: syslog功 ...

  9. ping下主服务器mysql_mysql主从同步配置

    配置mysql主从同步 主master : 192.168.8.10 从slave  :   192.168.8.11 1.配置主库: 1).授权给从数据库服务器 mysql>GRANT REP ...

最新文章

  1. KinectFusion基于深度的实时稠密三维重建TSDF开山之作
  2. Spring源码阅读(六)
  3. POS 客显 设备 显示 总价 单价 找零 收款 C# SerialPort 法
  4. bzoj4563放棋子
  5. Scrapy框架的学习(3.pipeline介绍以及多个爬虫的pipeline的使用)
  6. c语言课后答案第八章,C++第一至第八章课后习题答案
  7. 解决mysql锁表终极方法
  8. Python之旅.第八章.网络编程
  9. Linux中的sed命令,使用方法之一「替换字符串中的内容 」,以及「s/ / / 」和「s/ / /g」之间的区别
  10. 压力测试的轻量级具体做法
  11. 3D点云模型下载网站
  12. 电子商城战略分析(采用定性与定量分析方法)
  13. 计算机登录界面没有用户显示不出来,win7让administrator账户不出现在登陆界面方法...
  14. 【网络工具】使用 iperf测试 udp组播
  15. Python 保存 网页上的图片
  16. 抖音电商主播考核绩效直播运营KPI方案
  17. 关于1000桶水,其中一桶有毒,猪喝毒水后会在15分钟内死去,想用一个小时找到这桶毒水,至少需要几头猪?的问题
  18. 计算机测试是指,考驾照电脑测试是什么
  19. 带约束的K-means聚类算法
  20. AutoJs Pro 7.0.4-1 实战教程---史上最全快手极速版

热门文章

  1. Android开发之通过接口回调机制加载数据(源代码分享)
  2. DW数据仓库与ODS的区别
  3. android4.0代码下载总结
  4. Android 防止快速点击
  5. 算法------买卖股票的最佳时机
  6. JNI编程支持X86处理器的步骤
  7. 高速缓存的数据结构:拉链散列表
  8. 软件系统非功能测试方法,非功能测试方案模板
  9. python关闭浏览器、未过期的session_session.cookie_lifetime = 0时,为什么会话在浏览器关闭时不会过期?...
  10. uniapp禁止遮罩层下的页面滚动