我如何强制git pull覆盖每次拉动的所有内容? [英] How do I force git pull to overwrite everything on every pull?

查看:469
本文介绍了我如何强制git pull覆盖每次拉动的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我还有两个其他版本库,它们是从CENTRAL裸回购版中提取的:

我有一个CENTRAL裸存储库,有三个开发人员存储库,一个是实时服务器,另一个是测试/阶段服务器 - 每个服务器都从各自的分支中拉出来。



场景是这样的:我有一个 post-update 在CENTRAL回购站上的挂钩脚本,它可以自动访问测试和实时回购,并在每个回收站上运行一个pull命令。这将更新测试服务器和实时服务器,全部取决于哪个分支有新的提交。这一切都很好。



问题是这样的:在紧急情况下可能有时会在服务器上直接更新文件(通过ftp或其他),CENTRAL因为合并/覆盖冲突将发生,所以更新后脚本将失败。没有办法避免这种情况,这是不可避免的。



我想要发生的事情是这样的:我希望从实况和测试网站的拉动到总是在pull上覆盖/合并。 我无法找到一个很好的解决方案,只要总是强制覆盖本地文件。这是可能吗?如果是这样的话,这将会是一个很好的开发场景。 解决方案

真正理想的做法是不使用 pull ,但取而代之 fetch reset

  git fetch origin master 
git reset --hard FETCH_HEAD
git clean -df

(将 master 更改为您希望遵循的任何分支。)



pull 是围绕以某种方式合并更改而设计的,而 reset 是围绕简单地让本地副本匹配特定的提交。

c>取决于您系统的需求。


I have a CENTRAL bare repository that has three developer repositories pulling and pushing to it normally.

I also have two other repositories that pull from the CENTRAL bare repo: one is the live server, and the other is a test/stage server—each pulling from its own respective branch.

The scenario is this: I have a post-update hook script on the CENTRAL repo that automatically accesses the test and live repos and runs a pull command on each. This updates both test and live servers, all depending on what branch has new commits. This all works great.

The problem is this: there may be times in an emergency that files may be directly updated on the server (via ftp or whatever) and the CENTRAL post-update script will then fail since merge/overwrite conflicts will occur. There is no way to avoid this scenario, and it is inevitable.

What I would like to have happen is this: I want the pull from the live and test sites to always overwrite/merge on pull. Always. These repos will be pull-only as they are not for development.

In all my research, I cannot find a good solution to have a pull always force an overwrite of the local files. Is this at all possible? It would make for a great development scenario if so.

解决方案

Really the ideal way to do this is to not use pull at all, but instead fetch and reset:

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df

(Altering master to whatever branch you want to be following.)

pull is designed around merging changes together in some way, whereas reset is designed around simply making your local copy match a specific commit.

You may want to consider slightly different options to clean depending on your system's needs.

这篇关于我如何强制git pull覆盖每次拉动的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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