保持本地变化 [英] git pull keeping local changes

查看:150
本文介绍了保持本地变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何安全地更新(拉)一个git项目,保持特定的文件不变,即使存在上游变化?



myrepo / config / config.php

有没有办法,即使这个文件是在远程更改,当我git拉,其他所有更新,但这个文件是不变的(甚至没有合并) ?



PS。我需要做我所问的,因为我只写基于git的部署脚本。我无法将配置文件更改为模板。



因此,我需要编写不会丢失本地更改内容的更新脚本。我希望得到如下简单的内容:

  git假设-remote-unchanged file1 
git假设-remote-unchanged file2

然后 git pull

解决方案

有一个基于Git存储的简单解决方案。

  git储存
git拉动所有变更的东西,拉出所有新的东西,
git stash pop

存储弹出可能会有冲突。在你描述的情况下,实际上会有 config.php 的冲突。但是,解决冲突是很容易的,因为你知道你把什么放在隐藏处是你想要的。所以做到这一点:

  git checkout --theirs  -  config.php 


How can I safely update (pull) a git project, keeping specific files untouched, even if there's upstream changes?

myrepo/config/config.php

Is there a way, of, even if this file was being changed on remote, when I git pull, everything else is updated, but this file is unchanged (not even merged)?

PS. I need to do what I am asking because I'm only writing git-based deploy scripts. I cannot change config files to templates.

so, I need way to write update scripts that does not lose what was locally changed. I was hoping for something as simple as:

git assume-remote-unchanged file1
git assume-remote-unchanged file2

then git pull

解决方案

There is a simple solution based on Git stash. Stash everything that you've changed, pull all the new stuff, apply your stash.

git stash
git pull
git stash pop

On stash pop there may be conflicts. In the case you describe there would in fact be a conflict for config.php. But, resolving the conflict is easy because you know that what you put in the stash is what you want. So do this:

git checkout --theirs -- config.php

这篇关于保持本地变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆